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

[Bug]: Looked in to the Code and Do not understand a line that throws TestCaseAlreadyInUse #1109

Open
JesperHerrloff opened this issue Mar 5, 2024 · 0 comments
Labels

Comments

@JesperHerrloff
Copy link

What Happened

When use in Laravel Application with custom Module Structure, I didnt manage to get uses function which calls UsesCall Class to work as expected.

If for example:

uses(
    Tests\TestCase::class,
    Illuminate\Foundation\Testing\RefreshDatabase::class,
)->beforeEach(fn () => $this->seed(TestSeeder::class))->in('Feature', __DIR__.'/../modules/*/tests');

It throws this error as the testCase Class is not PHPUnit\Framework\TestCase; It is Tests\TestCase Which is logic as it is set in the uses function. If I comment out the condition if ($testCase->class !== TestCase::class) {

What if the check would check the class not equals the current class and is instance of TestCase::class for example

if ($testCase->class !== $class && $class instanceof TestCase::class) { 
     $testCase->class = $class;
}

Then it works as expected.

But It might be me that not understand the context of Why throwing an TestCaseAlreadyInUse Exception when Classes not Equals.

How to Reproduce

Install a fresh Laravel app, create a modules folder in Root. Create some modules
modules/User/tests/Feature
modules/Products/tests/Feature

Add a section for Modules in phpunit.xml

<testsuite name="Modules">
            <directory suffix="Test.php">modules/*/tests/Unit</directory>
            <directory suffix="Test.php">modules/*/tests/Feature</directory>
            <directory suffix="Test.php">modules/*/tests/Browser</directory>
        </testsuite>

Try to use uses in Pest.php in Feature, DIR./../modules/*/tests
Then it will throw TestCaseAlreadyInUse.

Then my Idea was to Move the uses function to the different TestFiles, but with the same Result.

Sample Repository

No response

Pest Version

v2.34.0

PHP Version

8.3.3

Operation System

macOS

Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant