0
votes

I am trying to create fixtures for my Symfony project. Unfortunately I'm plagued with the following error:

In LoadDataFixturesDoctrineCommand.php line 95:

Could not find any fixture services to load.

I have tried everything people suggested here. But no help.

My code is this:

    <?php

namespace App\DataFixtures;

use App\Entity\Users;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

class UserFixtures extends Fixture
{
    private $encoder;

    private function __construct(UserPasswordEncoderInterface $encoder){
        $this->encoder = $encoder;
    }

    public function load(ObjectManager $manager)
    {
        $user = new Users();
        $user->setUsername('wessel');
        $user->setPassword(
            $this->encoder->encodePassword($user, '123abc')
        );
        $user->setEmail('[email protected]');

        $manager->persist($user);
        $manager->flush();
    }
}

I have triend editing the services.yaml aswell, i added:

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

Unfortunately no help, what am i doing wrong?

1
Remove that stuff you added to services.yaml, your fixtures are autowired automatically, no need for that block.mblaettermann
I already removed it, i tried to test if it worked.Wvs
Is your fixture file in the correct folder?Jeroen
The fixture is in the automatically generated file: - src / DataFixtures / UserFixtures.phpWvs
Can you please add a complete console output , when you let a single PhpUnit test run?Calamity Jane

1 Answers

0
votes

Beware that with lastest HauteLook AliceBundle fixtures, the command to load fixtures is now :

php bin/console hautelook:fixtures:load

Using php bin/console doctrine:fixtures:load will result in a Could not find any fixture services to load. error

Additionally, when the command fails to purge the database, you can use

php bin/console hautelook:fixtures:load --purge-with-truncate