1

I'm using the DoctrineFixturesBundle. According to the documentation, any class that extends Fixture will be automatically wired up so the console knows how to handle it. However, despite my fixtures class extending Fixture (code below), I keep getting the following error:

Could not find any fixture services to load.

If I attempt to wire up the service manually in my services.yml file with:

services:
    AppBundle\DataFixtures\:
        resource: '../../src/AppBundle/DataFixtures/'
        tags: ['doctrine.fixture.orm']

I instead get:

In FileLoader.php line 168:

The file "../../src/AppBundle/DataFixtures" does not exist (in: /path/to/project/app/config) in /path/to/project/app/config/services.yml (which is being imported from "/path/to/project/app/config/config.yml").

In FileLocator.php line 71:

The file "../../src/AppBundle/DataFixtures" does not exist (in: /path/to/project/app/config).

The path to my data fixtures is /path/to/project/src/DataFixtures. The actual class file (AppFixtures.php) is:

namespace AppBundle\DataFixtures;

use AppBundle\Entity\Category;
use AppBundle\Entity\Product;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;

class AppFixtures extends Fixture
{
    public function load(ObjectManager $em)
    {
        $category = new Category();

        $category->setName("Test Category")
            ->setSlug()
            ->setDescription("This is only for test purposes");

        $fabricProduct = new Product();

        $fabricProduct->setName("Test OldProduct")
            ->setCanonicalPrice(2.45)
            ->setHasSale(false)
            ->setCategory($category)
            ->setSlug()
            ->setNumberInStock(45.25);

        $em->persist($category);
        $em->persist($fabricProduct);
        $em->flush();
    }
}

To preemptively answer the obvious questions, yes the bundle is registered correctly. And my services.yml file has the default autowiring:

services:
    # default configuration for services in *this* file
    _defaults:
        # automatically injects dependencies in your services
        autowire: true
        # automatically registers your services as commands, event subscribers, etc.
        autoconfigure: true
        # this means you cannot fetch services directly from the container via $container->get()
        # if you need to do this, you can override this setting on individual services
        public: false

Any ideas on what I'm doing wrong? According to all the documentation I've found, this should be working.

1 Answer 1

1

Solved it... with the way the default service wiring works in Symfony, it expects everything to be in the src/AppBundle directory. My fixtures were in a directory outside of that one (yet, still in the project directory, obviously). Moving my fixtures directory to be a child of src/AppBundle fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.