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

Add support for tests included in a test class via a trait #83

Open
chiefmyron opened this issue Feb 23, 2024 · 2 comments
Open

Add support for tests included in a test class via a trait #83

chiefmyron opened this issue Feb 23, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@chiefmyron
Copy link
Owner

Laravel has a number of test case classes where the actual tests are defined in traits that are used within the class definition:
image

Update the test file parser to identify traits used within a Test class, and add any test methods within the trait as test items.

@chiefmyron chiefmyron added the enhancement New feature or request label Feb 23, 2024
@chiefmyron chiefmyron self-assigned this Feb 23, 2024
@chiefmyron
Copy link
Owner Author

Test being executed from an included trait is reported in the teamcity logs as follows:

##teamcity[testSuiteStarted name='Illuminate\Tests\Integration\Database\EloquentTransactionWithAfterCommitTest' locationHint='php_qn://C:\Development\PHP\laravel\framework\tests\Integration\Database\EloquentTransactionWithAfterCommitTest.php::\Illuminate\Tests\Integration\Database\EloquentTransactionWithAfterCommitTest' flowId='12148']
##teamcity[testStarted name='testObserverIsCalledOnTestsWithAfterCommit' locationHint='php_qn://C:\Development\PHP\laravel\framework\tests\Integration\Database\EloquentTransactionWithAfterCommitTests.php::\Illuminate\Tests\Integration\Database\EloquentTransactionWithAfterCommitTest::testObserverIsCalledOnTestsWithAfterCommit' flowId='12148']
##teamcity[testFinished name='testObserverIsCalledOnTestsWithAfterCommit' duration='320' flowId='12148']

@chiefmyron
Copy link
Owner Author

This could be tricker than originally estimated. Taking the example class in the above description, there are two traits used by the test. However, both of these include additional traits, down multiple levels:

  • Illuminate\Tests\Integration\Database\EloquentTransactionWithAfterCommitTests
    • Orchestra\Testbench\Concerns\WithLaravelMigrations
      • Orchestra\Testbench\Concerns\InteractsWithWorkbench
        • Orchestra\Testbench\Concerns\InteractsWithPest
          • Orchestra\Testbench\Concerns\InteractsWithPHPUnit
            • Orchestra\Testbench\Concerns\InteractsWithTestCase
          • Orchestra\Testbench\Concerns\InteractsWithTestCase
        • Orchestra\Testbench\Concerns\InteractsWithPHPUnit
          • Orchestra\Testbench\Concerns\InteractsWithTestCase
        • Orchestra\Testbench\Concerns\InteractsWithTestCase
    • Illuminate\Foundation\Testing\DatabaseMigrations
      • Illuminate\Foundation\Testing\Traits\CanConfigureMigrationCommands

The vast majority of these nested traits do not actually include test methods, but are just helper methods. Will need to recursively parse potentially quite deep nested traits.

Could look at caching traits, but that has issues of its own - traits aren't included in the patterns used by the file watchers, since they don't need to conform to anything defined in the phpunit.xml configuration. If the trait is modified by the user, the extension has no way of picking up those changes, unless we add new watchers for each trait parsed. Either option could introduce some significant performance degredation.

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

No branches or pull requests

1 participant