Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2975d7

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

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

‎extension.neon‎

Lines changed: 4 additions & 0 deletions
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
-

‎src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php‎

Lines changed: 12 additions & 1 deletion
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(

‎src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php‎

Lines changed: 12 additions & 1 deletion
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(

‎tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php‎

Lines changed: 1 addition & 1 deletion
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

‎tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php‎

Lines changed: 1 addition & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /