doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.77k stars 224 forks source link

ODM Fixture service not found? #328

Open shehi opened 4 years ago

shehi commented 4 years ago

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.

SenseException commented 4 years ago

Have you tried doctrine.fixture.odm.mongodb as tag name?

n0wy commented 4 years ago

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)
    {
        ...
    }
}
jcruz97 commented 3 years ago

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)
    {
       ...
    }
}