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
base: trunk
Are you sure you want to change the base?
Changes from all commits
d2bce4b
78475e8
08e229a
d2a6b74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooo. Cool language feature I haven't seen before.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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' ); | ||
| } | ||
| } | ||
| 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' ); | ||
| } | ||
| } |
| 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' ); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.