Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class not found error with composer no-dev #225

Closed
fabwu opened this issue Dec 14, 2017 · 8 comments
Closed

Class not found error with composer no-dev #225

fabwu opened this issue Dec 14, 2017 · 8 comments

Comments

@fabwu
Copy link

fabwu commented Dec 14, 2017

I installed this bundle as recommended as a composer dev dependency. For my production deployment I do a composer install --optimize-autoloader --no-dev and this bundle gets removed.

composer also excute cache:clear --no-warmup afterwards and during that command I get this error:

[RuntimeException]                                                               
  An error occurred when executing the "'cache:clear --no-warmup'" command:        
  In FileLoader.php line 168:                                                      
                                                                                   
    Class AppBundle\Development\DataFixtures\CustomAbstractFixture not found in    
     /builds/app/plangate/app/config/services.yml (which is being imported from    
     "/builds/app/plangate/app/config/config.yml").                                
                                                                                   
  In BranchData.php line 11:                                                       
                                                                                   
    Class AppBundle\Development\DataFixtures\CustomAbstractFixture not found       
                                                                                   
  In CustomAbstractFixture.php line 10:                                            
                                                                                   
    Class Doctrine\Bundle\FixturesBundle\Fixture not found                         

The container try to autowire the fixtures but I use my fixtures only during development.

It's a minor issue but does anybody know how I can get rid of it?

@fabwu
Copy link
Author

fabwu commented Dec 18, 2017

I figured it out myself. Here is what if have done:

  1. Create a service_dev.yml with the following content:
services:
    # This part is important!
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    # Use the namespace where your fixtures are
    AppBundle\Development\DataFixtures\:
        resource: '../../src/AppBundle/Development/DataFixtures'
  1. Import it into config_dev.yml
  2. In your services.yml exclude the fixture folder:
services:
    AppBundle\:
        exclude: '../../src/AppBundle/{Entity,Repository,Tests,Development}'

After these changes you can have this bundle as a dev dependency and run composer install --optimize-autoloader --no-dev without an error.

@fabwu fabwu closed this as completed Dec 18, 2017
@inverse
Copy link

inverse commented Jan 2, 2018

Thanks for posting your fix! There must be a nicer way to handle this.

@alcaeus
Copy link
Member

alcaeus commented Jan 4, 2018

There must be a nicer way to handle this.

In general, if you only require this bundle as part of your dev dependencies, you should only create the appropriate services if the bundle is present. In this case, the service is generated due to the default config (which creates a service for every class it finds).

What confuses me is that the services are private and removed from the cached container if not used (which they shouldn't be in this case), so the service shouldn't be instantiated. Could you maybe get a trace for the original error or figure out what causes a fixture service to be instantiated?

@weaverryan
Copy link
Contributor

Ah, I just got more info about this error.

@alcaeus you're understanding is correct. However, the error comes earlier: when services.yml is being parsed. The service auto-registration code in Symfony tries to open CustomAbstractFixture so that it can make it a candidate to be a service. But it fails immediately because the parent class isn't found.

I think affects any project using DoctrineFixturesBundle as a dev dependency and deploying with --no-dev. But I don't think the fix is here in this bundle (the workaround listed above is great, btw, but it should be simpler). I've created an issue on Symfony symfony/symfony#25929

@alcaeus
Copy link
Member

alcaeus commented Jan 26, 2018

@weaverryan Thanks for investigating! Solving this in the container makes sense!

@inverse
Copy link

inverse commented Jan 31, 2018

Reverted changes suggested by @fabwu and upgraded to 3.4.4 and the problem looks like it's gone.

bug #25932 Don't stop PSR-4 service discovery if a parent class is missing (@derrabus)

@inverse
Copy link

inverse commented Apr 3, 2018

This issue came back on Symfony 4 with flex.

@alcaeus
Copy link
Member

alcaeus commented Apr 3, 2018

This issue came back on Symfony 4 with flex.

It's an issue in Symfony - nothing we can do here. Please report it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants