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

InvalidArgumentException : "App\Tests\DataFixtures\UserFixtures1" is not a registered fixture #57

Closed
klodoma opened this issue Mar 2, 2020 · 5 comments

Comments

@klodoma
Copy link

klodoma commented Mar 2, 2020

Hi,

This is probably not a but, maybe a configuration issue or something similar.
If the fixtures are not in use App\DataFixtures directory then I get the following error message:

InvalidArgumentException : "App\Tests\DataFixtures\UserFixtures1" is not a registered fixture
 D:\Projects\espos\repos\s55-demo\vendor\doctrine\data-fixtures\lib\Doctrine\Common\DataFixtures\Loader.php:135
 D:\Projects\espos\repos\s55-demo\vendor\liip\test-fixtures-bundle\src\Services\SymfonyFixturesLoaderWrapper.php:19
 D:\Projects\espos\repos\s55-demo\vendor\liip\test-fixtures-bundle\src\Services\FixturesLoaderFactory.php:44
 D:\Projects\espos\repos\s55-demo\vendor\liip\test-fixtures-bundle\src\Services\DatabaseTools\ORMSqliteDatabaseTool.php:75
 D:\Projects\espos\repos\s55-demo\vendor\liip\test-fixtures-bundle\src\Test\FixturesTrait.php:86
 D:\Projects\espos\repos\s55-demo\tests\Controller\SomeControllerTest.php:20

Any suggestion how to register App\Tests\DataFixtures\UserFixtures1 as fixture?

@alexislefebvre
Copy link
Collaborator

alexislefebvre commented Mar 4, 2020

Please share the code of your fixture.

What version of Symfony do you use ?

Do you use autowiring of services? It can work for your case: https://github.com/liip/LiipFunctionalTestBundle/issues/504#issuecomment-480640875

@klodoma
Copy link
Author

klodoma commented Mar 4, 2020

Please share the code of your fixture.

What version of Symfony do you use ?

Do you use autowiring of services? It can work for your case: liip/LiipFunctionalTestBundle#504 (comment)

I'm playing around with the symfony demo app, so it's Symfony 5. But with Symfony 4 I get the same issue.
Have a look here for the test and fixture:
https://github.com/klodoma/symfony-demo/tree/master/tests/DataFixtures

I have the impression that the problem comes from the fact that the fixture is not found in /src/DataFixtures because with that it works.

@alexislefebvre
Copy link
Collaborator

I have the impression that the problem comes from the fact that the fixture is not found in /src/DataFixtures because with that it works.

IIRC, this bundle relies on DoctrineFixturesBundle. According to its documentation:

This command looks for all services tagged with doctrine.fixture.orm. If you're using the default service configuration, any class that implements ORMFixtureInterface (for example, those extending from Fixture) will automatically be registered with this tag.

Source: https://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html#loading-fixtures

Maybe the class should implement ORMFixtureInterface, but maybe it' not enough to declare fixtures in tests/.

Here is how they are declared in internal tests, with a service tag:

Liip\Acme\Tests\App\DataFixtures\ORM\:
resource: 'DataFixtures/ORM/*'
tags: ['doctrine.fixture.orm']

Maybe you can use a config like this in your config_test.yml in order to declare fixtures that are not in src/.

@alexislefebvre
Copy link
Collaborator

Did the last comment helped you?

@klodoma
Copy link
Author

klodoma commented May 2, 2022

I think so, as I didn't followed it up. Let's close this.

@klodoma klodoma closed this as completed May 2, 2022
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

2 participants