Skip to content

Commit c7aef31

Browse files
committedApr 2, 2018
AssertSameDifferentTypesRule is obsolete
1 parent a4b4ff3 commit c7aef31

8 files changed

+147
-151
lines changed
 

‎README.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ This extension provides following features:
1313
* `getMock()` called on `MockBuilder` is also supported.
1414
* Interprets `Foo|PHPUnit_Framework_MockObject_MockObject` in phpDoc so that it results in an intersection type instead of a union type.
1515
* Defines early terminating method calls for the `PHPUnit\Framework\TestCase` class to prevent undefined variable errors.
16-
17-
It also contains this framework-specific rule (can be enabled separately):
18-
19-
* Check that both values passed to `assertSame()` method are of the same type.
16+
* Specifies types of expressions passed to various `assert` methods like `assertInstanceOf`, `assertTrue`, `assertInternalType` etc.
17+
* Combined with PHPStan's level 4, it points out always-true and always-false asserts like `assertTrue(true)` etc.
2018

2119
It also contains this strict framework-specific rules (can be enabled separately):
2220

@@ -88,9 +86,3 @@ To perform framework-specific checks, include also this file:
8886
```
8987
- vendor/phpstan/phpstan-phpunit/rules.neon
9088
```
91-
92-
To perform addition strict PHPUnit checks, include also this file:
93-
94-
```
95-
- vendor/phpstan/phpstan-phpunit/strictRules.neon
96-
```

‎phpstan.neon

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
includes:
22
- extension.neon
33
- rules.neon
4-
- strictRules.neon
54
- vendor/phpstan/phpstan-strict-rules/rules.neon
65

76
parameters:

‎rules.neon

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
rules:
2-
- PHPStan\Rules\PHPUnit\AssertSameDifferentTypesRule
2+
- PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule
3+
- PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule
4+
- PHPStan\Rules\PHPUnit\AssertSameWithCountRule

‎src/Rules/PHPUnit/AssertSameDifferentTypesRule.php

-50
This file was deleted.

‎strictRules.neon

-4
This file was deleted.

‎tests/Rules/PHPUnit/AssertSameDifferentTypesRuleTest.php

-85
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\PHPUnit;
4+
5+
use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule;
6+
use PHPStan\Rules\Rule;
7+
use PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension;
8+
9+
class AssertSameMethodDifferentTypesRuleTest extends \PHPStan\Testing\RuleTestCase
10+
{
11+
12+
protected function getRule(): Rule
13+
{
14+
return new ImpossibleCheckTypeMethodCallRule(true);
15+
}
16+
17+
/**
18+
* @return \PHPStan\Type\MethodTypeSpecifyingExtension[]
19+
*/
20+
protected function getMethodTypeSpecifyingExtensions(): array
21+
{
22+
return [
23+
new AssertMethodTypeSpecifyingExtension(),
24+
];
25+
}
26+
27+
public function testRule(): void
28+
{
29+
$this->analyse([__DIR__ . '/data/assert-same.php'], [
30+
[
31+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
32+
10,
33+
],
34+
[
35+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
36+
11,
37+
],
38+
[
39+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
40+
12,
41+
],
42+
[
43+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
44+
13,
45+
],
46+
[
47+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
48+
14,
49+
],
50+
[
51+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
52+
39,
53+
],
54+
[
55+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to true.',
56+
44,
57+
],
58+
[
59+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
60+
45,
61+
],
62+
[
63+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to true.',
64+
46,
65+
],
66+
[
67+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
68+
47,
69+
],
70+
[
71+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to true.',
72+
48,
73+
],
74+
[
75+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
76+
51,
77+
],
78+
[
79+
'Call to method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
80+
52,
81+
],
82+
]);
83+
}
84+
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\PHPUnit;
4+
5+
use PHPStan\Rules\Comparison\ImpossibleCheckTypeStaticMethodCallRule;
6+
use PHPStan\Rules\Rule;
7+
use PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension;
8+
9+
class AssertSameStaticMethodDifferentTypesRuleTest extends \PHPStan\Testing\RuleTestCase
10+
{
11+
12+
protected function getRule(): Rule
13+
{
14+
return new ImpossibleCheckTypeStaticMethodCallRule(true);
15+
}
16+
17+
/**
18+
* @return \PHPStan\Type\StaticMethodTypeSpecifyingExtension[]
19+
*/
20+
protected function getStaticMethodTypeSpecifyingExtensions(): array
21+
{
22+
return [
23+
new AssertStaticMethodTypeSpecifyingExtension(),
24+
];
25+
}
26+
27+
public function testRule(): void
28+
{
29+
$this->analyse([__DIR__ . '/data/assert-same.php'], [
30+
[
31+
'Call to static method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
32+
16,
33+
],
34+
[
35+
'Call to static method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
36+
17,
37+
],
38+
[
39+
'Call to static method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
40+
18,
41+
],
42+
[
43+
'Call to static method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
44+
53,
45+
],
46+
[
47+
'Call to static method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
48+
54,
49+
],
50+
[
51+
'Call to static method PHPUnit\Framework\Assert::assertSame() will always evaluate to false.',
52+
55,
53+
],
54+
]);
55+
}
56+
57+
}

0 commit comments

Comments
 (0)
Please sign in to comment.