diff --git a/README.md b/README.md index 97d7eff..2ff1f3f 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,39 @@ To perform framework-specific checks, include also this file: ``` + + +## Codeception parameters + +This extension works well with [Codeception](https://github.com/Codeception/Codeception) too. + +[Unit tests](https://codeception.com/docs/05-UnitTests) are already recognised by default; +[Functional tests](https://codeception.com/docs/04-FunctionalTests) and +[Acceptance tests](https://codeception.com/docs/03-AcceptanceTests) instead have to be configured +manually since assertion classes are generated at runtime with different namespaces and class names. + +Here's an example configuration: + +``` +services: + - + class: PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension + arguments: + classWithAssertionMethods: My\CustomNamespace\_support\FunctionalTester + tags: + - phpstan.typeSpecifier.methodTypeSpecifyingExtension + - + class: PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension + arguments: + classWithAssertionMethods: My\CustomNamespace\_support\FunctionalTester + tags: + - phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension + +parameters: + earlyTerminatingMethodCalls: + My\CustomNamespace\_support\FunctionalTester: + - fail + Codeception\Scenario: + - incomplete + - skip +``` diff --git a/extension.neon b/extension.neon index 3395ec1..2b1e59c 100644 --- a/extension.neon +++ b/extension.neon @@ -20,10 +20,14 @@ services: - phpstan.typeSpecifier.functionTypeSpecifyingExtension - class: PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension + arguments: + classWithAssertionMethods: PHPUnit\Framework\TestCase tags: - phpstan.typeSpecifier.methodTypeSpecifyingExtension - class: PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension + arguments: + classWithAssertionMethods: PHPUnit\Framework\Assert tags: - phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension - diff --git a/src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php b/src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php index 243a7d4..88cf72f 100644 --- a/src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php +++ b/src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php @@ -14,9 +14,20 @@ class AssertMethodTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension { + /** @var class-string */ + private $classWithAssertionMethods; + /** @var TypeSpecifier */ private $typeSpecifier; + /** + * @param class-string $classWithAssertionMethods + */ + public function __construct(string $classWithAssertionMethods) + { + $this->classWithAssertionMethods = $classWithAssertionMethods; + } + public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void { $this->typeSpecifier = $typeSpecifier; @@ -24,7 +35,7 @@ public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void public function getClass(): string { - return 'PHPUnit\Framework\TestCase'; + return $this->classWithAssertionMethods; } public function isMethodSupported( diff --git a/src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php b/src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php index f33ee7a..bf475d0 100644 --- a/src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php +++ b/src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php @@ -14,9 +14,20 @@ class AssertStaticMethodTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension { + /** @var class-string */ + private $classWithAssertionMethods; + /** @var TypeSpecifier */ private $typeSpecifier; + /** + * @param class-string $classWithAssertionMethods + */ + public function __construct(string $classWithAssertionMethods) + { + $this->classWithAssertionMethods = $classWithAssertionMethods; + } + public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void { $this->typeSpecifier = $typeSpecifier; @@ -24,7 +35,7 @@ public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void public function getClass(): string { - return 'PHPUnit\Framework\Assert'; + return $this->classWithAssertionMethods; } public function isStaticMethodSupported( diff --git a/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php b/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php index f840cea..da4a0c1 100644 --- a/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php @@ -24,7 +24,7 @@ protected function getRule(): Rule protected function getMethodTypeSpecifyingExtensions(): array { return [ - new AssertMethodTypeSpecifyingExtension(), + new AssertMethodTypeSpecifyingExtension('PHPUnit\Framework\TestCase'), ]; } diff --git a/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php b/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php index 9d1b52e..f4032d2 100644 --- a/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php @@ -24,7 +24,7 @@ protected function getRule(): Rule protected function getStaticMethodTypeSpecifyingExtensions(): array { return [ - new AssertStaticMethodTypeSpecifyingExtension(), + new AssertStaticMethodTypeSpecifyingExtension('PHPUnit\Framework\Assert'), ]; }