问题
i know this question has been asked already multiple times:
- Symfony 3.4 and Fixtures Bundle issue with bundle version 3.0
- Symfony 3.4.0 Could not find any fixture services to load
- Symfony Doctrine can't find fixtures to load
- Could not find any fixture services to load - Symfony 3.2
None of the above actually helped me out. That said, this is my configuration:
Composer.json
"require": {
"php": ">=7.0",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
....
},
"require-dev": {
....
"doctrine/doctrine-fixtures-bundle": "^3.0",
}
I'm using a company-developed Bundle which worked fine until the last version of the above (last tested and working configuration had PHP 5.6, Doctrine bundle ^1.6,doctrine orm ^2.5, fixture bundle ^3.0).
This bundle has some Fixture inside VendorName/BundleName/DataFixtures/ORM, all the fixtures have the following declaration:
Class MyFixture1 extends Fixture implements OrderedFixtureInterface,FixtureInterface, ContainerAwareInterface{
...
}
Inside this bundle there's a services.yml file, loaded by this:
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
VendorName/BundleName/Resources/config/Services.yml i tried different configurations:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
VendorName\BundleName\:
resource: '../../*'
# you can exclude directories or files but if a service is unused, it's removed anyway
exclude: '../../{Entity,Repository,Tests,EventListener}'
I tried expliciting searching inside DataFixtures:
VendorName/BundleName\DataFixtures\:
resource: '../../src/VendorName/BundleName/DataFixtures'
tags: ['doctrine.fixture.orm']
And even manually configure the service:
VendorName\BundleName\DataFixtures\ORM\MyFixture1:
class: VendorName/BundleNamee\DataFixtures\ORM\MyFixture1
tags: ['doctrine.fixture.orm']
But unfortunately it keeps giving the error. Any idea of what i'm doing wrong? Long time ago it was possible to manually specify to the fixture command which bundle to look in, but now it's not possible anymore
UPDATE 1: Sorry guys forgot to point the error message: "Could not find any fixture services to load"
回答1:
For everyone landing here i solved my problem, what i can tell you is:
- Double check you enabled the Bundle in the AppKernel
- Clear your symfony cache using the command php bin/console cache:clear --env=dev (or env=prod)
- Manually delete cache folder
回答2:
The accepted answer helped point me in the right direction to get this working. Though cache could indeed be a problem, having Fixtures in your own bundles does require you to register them.
Using SF 5.1.* I created a services_dev.yaml
file and added in:
services:
// other config
Namespace\Registered\In\Composer\For\Fixtures\:
resource: '../vendor/path/registered/in/composer/to/fixtures'
tags: ['doctrine.fixture.orm']
Then indeed, clear cache and it should work.
Added *_dev
to the services.yaml
file as it's a way for Symfony to only load it in when in your in a dev environment (per APP_ENV
Environment variable).
来源:https://stackoverflow.com/questions/50984433/could-not-find-any-fixture-services-to-load