-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97c1c8d
commit bb82f34
Showing
5 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
43 changes: 43 additions & 0 deletions
43
tests/phpstan/tests/Rules/ApplyFiltersTypedDynamicFunctionReturnTypeExtensionTest.php
This file contains 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,43 @@ | ||
<?php | ||
namespace WP_Rocket\Tests\phpstan\tests\Rules; | ||
|
||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleLevelHelper; | ||
use PHPStan\Testing\RuleTestCase; | ||
use PHPStan\Type\FileTypeMapper; | ||
use WP_Rocket\Tests\phpstan\Rules\ApplyFiltersTypedDynamicFunctionReturnTypeExtension; | ||
|
||
class ApplyFiltersTypedDynamicFunctionReturnTypeExtensionTest extends RuleTestCase { | ||
|
||
protected function getRule(): Rule { | ||
return new ApplyFiltersTypedDynamicFunctionReturnTypeExtension($this->getContainer()->getByType(FileTypeMapper::class), $this->getContainer()->getByType(RuleLevelHelper::class)); | ||
} | ||
|
||
public function testShouldRaiseError() { | ||
$this->analyse([__DIR__ . '/../data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/not-valid.php'], [ | ||
[ | ||
'Missing docblock for wpm_apply_filters_typed call.', | ||
3, | ||
], | ||
[ | ||
'Expected 2 @param tags, found 0.', | ||
8, | ||
], | ||
[ | ||
'Expected 2 @param tags, found 1.', | ||
13, | ||
], | ||
]); | ||
} | ||
|
||
public function testShouldNotRaiseError() { | ||
$this->analyse([__DIR__ . '/../data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/valid.php'], []); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
// path to your project's phpstan.neon, or extension.neon in case of custom extension packages | ||
// this is only necessary if your custom rule relies on some extra configuration and other extensions | ||
return [__DIR__ . '/../data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/extension.neon']; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/phpstan/tests/data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/extension.neon
This file contains 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,2 @@ | ||
includes: | ||
- ../../../../../vendor/szepeviktor/phpstan-wordpress/extension.neon |
13 changes: 13 additions & 0 deletions
13
tests/phpstan/tests/data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/not-valid.php
This file contains 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,13 @@ | ||
<?php | ||
|
||
wpm_apply_filters_typed('test', 100); | ||
|
||
/** | ||
* | ||
*/ | ||
wpm_apply_filters_typed('test', 100); | ||
|
||
/** | ||
* @param string $number test. | ||
*/ | ||
wpm_apply_filters_typed('test', 100); |
6 changes: 6 additions & 0 deletions
6
tests/phpstan/tests/data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/valid.php
This file contains 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,6 @@ | ||
<?php | ||
/** | ||
* @param string $name test. | ||
* @param string $number test. | ||
*/ | ||
wpm_apply_filters_typed('test', 100); |