data-fixtures
data-fixtures copied to clipboard
ODM Fixture service not found?
service:
<?php
namespace App\Resources\DataFixtures\MongoDB;
use App\Domain\Document\User;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Faker\Factory;
use Faker\ORM\Doctrine\Populator;
use FoundersLane\UserBundle\Database\Contract\Activatable;
class UserDataLoader extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager): void
{
// stuff here
}
}
service registration is as such:
services:
# ... all other stuff here, including autowiring = true
App\Resources\DataFixtures\MongoDB\:
resource: '%kernel.project_dir%/src/Resources/DataFixtures/MongoDB'
tags: ['doctrine.fixture.odm']
./bin/console debug:autowiring --all -- Fixture:
Autowirable Types
=================
The following classes & interfaces can be used as type-hints when autowiring:
(only showing classes/interfaces matching Fixture)
App\Resources\DataFixtures\MongoDB\UserDataLoader
Load data fixtures from bundles.
Doctrine\Bundle\MongoDBBundle\Command\LoadDataFixturesDoctrineODMCommand
FoundersLane\UserBundle\DataFixtures\Processor\UserProcessor
Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.
YET, ./bin/console doctrine:mongodb:fixtures:load -n -vvv tells me:
[ERROR] Could not find any fixture services to load.
What am I doing wrong? Thanks.
Have you tried doctrine.fixture.odm.mongodb as tag name?
Got similar issue.
What fixed it was extending the fixture with Doctrine\Bundle\MongoDBBundle\Fixture\Fixture. I was using Doctrine\Bundle\FixturesBundle\Fixture before :facepalm:
After changing to MongoDBBundlecommand sees and run it. I've removed it from services config after that and it's still being found by the command.
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends \Doctrine\Bundle\MongoDBBundle\Fixture\Fixture
{
public function load(ObjectManager $manager)
{
...
}
}
You can also declare your package and put an alias, the fixture package is also not needed as the MongoDBBundle one extends the FixturesInterface uses the ORM one.
<?php
namespace App\DataFixtures;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Bundle\MongoDBBundle\Fixture\Fixture as MongoFixture;
class AppFixtures extends MongoFixture
{
public function load(ObjectManager $manager)
{
...
}
}