Skip to content

Commit c2975d7

Browse files
committed
Make assertion types class a parameter
1 parent 783a04d commit c2975d7

5 files changed

+30
-4
lines changed

Diff for: extension.neon

+4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ services:
2020
- phpstan.typeSpecifier.functionTypeSpecifyingExtension
2121
-
2222
class: PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension
23+
arguments:
24+
classWithAssertionMethods: PHPUnit\Framework\TestCase
2325
tags:
2426
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
2527
-
2628
class: PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension
29+
arguments:
30+
classWithAssertionMethods: PHPUnit\Framework\Assert
2731
tags:
2832
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
2933
-

Diff for: src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,28 @@
1414
class AssertMethodTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
1515
{
1616

17+
/** @var class-string */
18+
private $classWithAssertionMethods;
19+
1720
/** @var TypeSpecifier */
1821
private $typeSpecifier;
1922

23+
/**
24+
* @param class-string $classWithAssertionMethods
25+
*/
26+
public function __construct(string $classWithAssertionMethods)
27+
{
28+
$this->classWithAssertionMethods = $classWithAssertionMethods;
29+
}
30+
2031
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
2132
{
2233
$this->typeSpecifier = $typeSpecifier;
2334
}
2435

2536
public function getClass(): string
2637
{
27-
return 'PHPUnit\Framework\TestCase';
38+
return $this->classWithAssertionMethods;
2839
}
2940

3041
public function isMethodSupported(

Diff for: src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,28 @@
1414
class AssertStaticMethodTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
1515
{
1616

17+
/** @var class-string */
18+
private $classWithAssertionMethods;
19+
1720
/** @var TypeSpecifier */
1821
private $typeSpecifier;
1922

23+
/**
24+
* @param class-string $classWithAssertionMethods
25+
*/
26+
public function __construct(string $classWithAssertionMethods)
27+
{
28+
$this->classWithAssertionMethods = $classWithAssertionMethods;
29+
}
30+
2031
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
2132
{
2233
$this->typeSpecifier = $typeSpecifier;
2334
}
2435

2536
public function getClass(): string
2637
{
27-
return 'PHPUnit\Framework\Assert';
38+
return $this->classWithAssertionMethods;
2839
}
2940

3041
public function isStaticMethodSupported(

Diff for: tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function getRule(): Rule
2424
protected function getMethodTypeSpecifyingExtensions(): array
2525
{
2626
return [
27-
new AssertMethodTypeSpecifyingExtension(),
27+
new AssertMethodTypeSpecifyingExtension('PHPUnit\Framework\TestCase'),
2828
];
2929
}
3030

Diff for: tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function getRule(): Rule
2424
protected function getStaticMethodTypeSpecifyingExtensions(): array
2525
{
2626
return [
27-
new AssertStaticMethodTypeSpecifyingExtension(),
27+
new AssertStaticMethodTypeSpecifyingExtension('PHPUnit\Framework\Assert'),
2828
];
2929
}
3030

0 commit comments

Comments
 (0)