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

ODM Fixture service not found? #328

Open
shehi opened this issue Nov 13, 2019 · 3 comments
Open

ODM Fixture service not found? #328

shehi opened this issue Nov 13, 2019 · 3 comments

Comments

@shehi
Copy link

shehi commented Nov 13, 2019

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
Copy link
Member

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

@n0wy
Copy link

n0wy commented Jul 26, 2020

Got similar issue.
What fixed it was extending the fixture with Doctrine\Bundle\MongoDBBundle\Fixture\Fixture. I was using Doctrine\Bundle\FixturesBundle\Fixture before 🤦
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
Copy link

jcruz97 commented Mar 19, 2021

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

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