zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
611 stars 63 forks source link

RuntimeException: Cannot get Foundry's configuration. Possible Bug? #500

Closed justpilot closed 10 months ago

justpilot commented 10 months ago

Hello,

I'm experiencing a strange behavior during my tests. I'm getting this error at the end:

RuntimeException: Cannot get Foundry's configuration. If using faker in a data provider, consider passing attributes as a callable.

I have a file AdminLoginTest.php in /tests/Functional.

<?php

declare(strict_types=1);

namespace App\Tests\Functional;

use App\Factory\UserFactory;
use Zenstruck\Browser\HttpOptions;

class AdminLoginTest extends ApiTestCase
{
    public function testAdminUserLogin(): void
    {
        $user = UserFactory::new()->withRoles(['ROLE_ADMIN'])->create();

        dump($user);

        $this->browser()
            ->post('/api/admin/accounts/status', HttpOptions::json([
                'username' => $user->getUsername()
            ]))
            ->assertSuccessful()
            ->assertJson()
            ->dump();
    }
}

The strange thing is, just by renaming the file to XAdminLoginTest.php and the Class to XAdminLoginTest every test runs fine. If I run a single Test "XAdminLoginTest", then the message reappears. If the test is the first Test on the list, then the message reappears.

Any ideas?

Symfony 6.3
api-platform/core                   v3.1.15            Build a fully-featured hypermedia or GraphQL API in minutes!
dama/doctrine-test-bundle           v7.2.1             Symfony bundle to isolate doctrine database tests and improve test performance
doctrine/data-fixtures              1.6.7              Data Fixtures for all Doctrine Object Managers
zenstruck/assert                    v1.4.0             Standalone, lightweight, framework agnostic, test assertion library.
zenstruck/browser                   v1.4.0             A fluent interface for your Symfony functional tests.
zenstruck/callback                  v1.5.0             Callable wrapper to validate and inject arguments.
zenstruck/foundry                   v1.35.0            A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
zenstruck/mailer-test               v1.3.0             Alternative, opinionated helpers for testing emails sent with symfony/mailer.
justpilot commented 10 months ago

Symfony Docs: Enable Foundry in your TestCase

Add the Factories trait for tests using factories