Import AdditionalAssertions to base test case when generating Pest tests #733
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR modifies the strategy for importing
AdditionalAssertions
into Pest tests, changing from importing it in every test to importing it once intest/TestCase.php
(from which Pest tests extend). The original idea was not to alter files beyond those generated, but doing so avoids boilerplate and streamlines the codebase. Check #726 (comment)What changed
If validation statements are detected,
PestTestGenerator
checks if the filetest/TestCase.php
exists. If it does, it verifies whetherAdditionalAssertions
is imported. If not, the following modifications are made:A test has been added to validate this behavior and check that these alterations only happen once.
The
use JMac\Testing\Traits\AdditionalAssertions;
andpest()->use(AdditionalAssertions::class);
lines are no longer added to the individual test files. The test fixtures have been updated to reflect this change.Note
The only caveat with this strategy is that the regex might require updating if the
TestCase
content changes in future Laravel versions.How to test locally
Install:
Point the Blueprint package to this fork and branch.
Then, initialize:
Comment out PHPUnit and uncomment Pest:
Paste this in the
draft.yaml
:Generate:
Blueprint must say test base case was updated:
Go to
tests/Pest.php
and useRefreshDatabase
:Then run the generated tests:
Tests should run without errors.