Chlouis's avatar

Pest global datasets not allowed in modular project ?

I'm working on a modular project (app\Modules\*MyModule*) and my pest tests are in app\Modules\*MyModule*\Tests\Feature. On Laravel 10.x and Pest 1.x with global datasets.

Now i'm upgrading Pest on 2.x., and my global datasets (mostly different kind of users) are broken ! (tests\Datasets\Users.php)

dataset('Super-administrator 2FA enabled', function () {
    return [
        'Super Administrator' => [
            function () {
                return User::factory()->with2faEnabled()->create(['role' => 'super-admin']);
            }
        ],
    ];
});

Terminal error : Typed static property P\App\Modules\xx\Tests\Feature\XxxxTest::$__latestDescription must not be accessed before initialization.

After research and tests (fresh L10 install and Pest2), it's seem impossible ! A copy of my dataset directly in the test file works. A dataset file in tests\Datasets.php or tests\Datasets\Users.php works for "root" tests in \tests\Feature**.php. Never in module folder :(

Any ideas or tips ?

Thanks

0 likes
3 replies
Chlouis's avatar

Sadly, @LaryAI, it doesn't work !

On fresh Laravel 10, pest 2.x, pest-plugin-laravel with dummy tests (copy/paste from Pest documentation).

Always the same thing, on tests/Feature, datasets work but in modular folder it doesn't.

My Pest.php :

require_once 'Users.php';

uses(
    Tests\TestCase::class,
    Illuminate\Foundation\Testing\RefreshDatabase::class,
)->in(
    'Feature',
    '../app/Modules/*/Tests/Feature'
);
Chlouis's avatar

I guess, i'll recreate my own dataset function and logic...

Please or to participate in this conversation.