Repository navigation
Build/Test Tools: Add tests for the PHPStan extensions #15850
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
Closed
johnbillion
wants to merge
18
commits into
WordPress:trunk
from
johnbillion:66634-phpstan-extension-tests
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d2bce4b
Build/Test Tools: Add tests for the PHPStan extensions.
johnbillion 78475e8
Merge branch 'trunk' into 66634-phpstan-extension-tests
johnbillion 08e229a
Build/Test Tools: Test that `@phpstan-param` types a filtered value.
johnbillion d2a6b74
Apply suggestions from code review
johnbillion 05661e3
Merge branch 'trunk' into 66634-phpstan-extension-tests
johnbillion 7ec762d
Merge branch 'trunk' into 66634-phpstan-extension-tests
westonruter 6f03dc1
Build/Test Tools: Avoid casting a dynamic call name to string.
westonruter 7ea685d
Build/Test Tools: Remove an unused import from `HookDocumentationRule…
westonruter 3ee8e76
Build/Test Tools: Catch duplicated tags in the hash notation tests.
westonruter ee23bc4
Build/Test Tools: Run the PHPStan extension tests after reporting.
westonruter 728278a
Build/Test Tools: Test the parser redefinition in `base.neon`.
westonruter 6243357
Build/Test Tools: Say where the extension tests now run in CI.
westonruter 387d35f
Build/Test Tools: Add the configuration `ReflectionParserTest` runs w…
westonruter bf59296
Build/Test Tools: Make the traversal reset test able to fail.
westonruter 1ba9c3d
Build/Test Tools: Raise the memory limit for the PHPStan extension te…
westonruter ffbbbe5
Build/Test Tools: Keep `ReflectionParserTest` from deadlocking on PHP…
westonruter 0832a5f
Build/Test Tools: Skip the PHPStan extension tests when setup failed.
westonruter b550d15
Build/Test Tools: Correct which docblocks `HashNotationVisitor` rewri…
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/phpstan/Tests/ApplyFiltersDynamicFunctionReturnTypeExtensionTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
| /** | ||
| * Tests for ApplyFiltersDynamicFunctionReturnTypeExtension. | ||
| * | ||
| * @package WordPress | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace WordPress\PHPStan\Tests; | ||
|
|
||
| use PHPStan\Testing\TypeInferenceTestCase; | ||
|
|
||
| /** | ||
| * Checks the type PHPStan infers for a filtered value against the `assertType()` | ||
| * calls in the fixtures. | ||
| */ | ||
| final class ApplyFiltersDynamicFunctionReturnTypeExtensionTest extends TypeInferenceTestCase { | ||
|
|
||
| /** | ||
| * Gathers the assertions from the fixtures. | ||
| * | ||
| * @return iterable<string, mixed[]> | ||
| */ | ||
| public function data_file_asserts(): iterable { | ||
| yield from self::gatherAssertTypes( __DIR__ . '/data/apply-filters.php' ); | ||
| yield from self::gatherAssertTypes( __DIR__ . '/data/ApplyFiltersTestClass.php' ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider data_file_asserts | ||
| * | ||
| * @param string $assert_type Kind of assertion. | ||
| * @param string $file Fixture file. | ||
| * @param mixed ...$args Assertion arguments. | ||
| */ | ||
| public function test_file_asserts( string $assert_type, string $file, ...$args ): void { | ||
| $this->assertFileAsserts( $assert_type, $file, ...$args ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the configuration registering the extension and the visitors it relies on. | ||
| * | ||
| * @return list<string> | ||
| */ | ||
| public static function getAdditionalConfigFiles(): array { | ||
| return array( __DIR__ . '/tests.neon' ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
| /** | ||
| * Tests for GlobalDocBlockVisitor. | ||
| * | ||
| * @package WordPress | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace WordPress\PHPStan\Tests; | ||
|
|
||
| use PHPStan\Testing\TypeInferenceTestCase; | ||
|
|
||
| /** | ||
| * Checks the type PHPStan infers for an imported global against the `assertType()` | ||
| * calls in the fixtures. | ||
| */ | ||
| final class GlobalDocBlockVisitorTest extends TypeInferenceTestCase { | ||
|
|
||
| /** | ||
| * Gathers the assertions from the fixtures. | ||
| * | ||
| * @return iterable<string, mixed[]> | ||
| */ | ||
| public function data_file_asserts(): iterable { | ||
| yield from self::gatherAssertTypes( __DIR__ . '/data/global-docblock.php' ); | ||
| yield from self::gatherAssertTypes( __DIR__ . '/data/GlobalDocBlockTestClass.php' ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider data_file_asserts | ||
| * | ||
| * @param string $assert_type Kind of assertion. | ||
| * @param string $file Fixture file. | ||
| * @param mixed ...$args Assertion arguments. | ||
| */ | ||
| public function test_file_asserts( string $assert_type, string $file, ...$args ): void { | ||
| $this->assertFileAsserts( $assert_type, $file, ...$args ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the configuration registering the visitor. | ||
| * | ||
| * @return list<string> | ||
| */ | ||
| public static function getAdditionalConfigFiles(): array { | ||
| return array( __DIR__ . '/tests.neon' ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
| /** | ||
| * Tests the types PHPStan infers once HashNotationVisitor has translated a hash. | ||
| * | ||
| * @package WordPress | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace WordPress\PHPStan\Tests; | ||
|
|
||
| use PHPStan\Testing\TypeInferenceTestCase; | ||
|
|
||
| /** | ||
| * Checks the `assertType()` calls in the hash notation fixture. | ||
| */ | ||
| final class HashNotationTypeTest extends TypeInferenceTestCase { | ||
|
|
||
| /** | ||
| * Gathers the assertions from the fixture. | ||
| * | ||
| * @return iterable<string, mixed[]> | ||
| */ | ||
| public function data_file_asserts(): iterable { | ||
| yield from self::gatherAssertTypes( __DIR__ . '/data/hash-notation.php' ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider data_file_asserts | ||
| * | ||
| * @param string $assert_type Kind of assertion. | ||
| * @param string $file Fixture file. | ||
| * @param mixed ...$args Assertion arguments. | ||
| */ | ||
| public function test_file_asserts( string $assert_type, string $file, ...$args ): void { | ||
| $this->assertFileAsserts( $assert_type, $file, ...$args ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the configuration registering the visitor. | ||
| * | ||
| * @return list<string> | ||
| */ | ||
| public static function getAdditionalConfigFiles(): array { | ||
| return array( __DIR__ . '/tests.neon' ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooo. Cool language feature I haven't seen before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah unfortunately PHPUnit collects all data provider data for all tests before starting (so it can show progress) so it doesn't actually provide the memory benefit that a generator usually does. Neat though.