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 fdda536

Browse files
Merge commit 'f92aab7' into 1.1.x
2 parents ade3496 + f92aab7 commit fdda536

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\Testing\RuleTestCase;
8+
9+
/**
10+
* @extends RuleTestCase<ImpossibleCheckTypeMethodCallRule>
11+
*/
12+
class ImpossibleCheckTypeMethodCallRuleTest extends RuleTestCase
13+
{
14+
15+
protected function getRule(): Rule
16+
{
17+
return self::getContainer()->getByType(ImpossibleCheckTypeMethodCallRule::class);
18+
}
19+
20+
public function testRule(): void
21+
{
22+
$this->analyse([__DIR__ . '/data/impossible-assert-method-call.php'], [
23+
[
24+
'Call to method PHPUnit\Framework\Assert::assertEmpty() with array{} will always evaluate to true.',
25+
14,
26+
],
27+
[
28+
'Call to method PHPUnit\Framework\Assert::assertEmpty() with array{1, 2, 3} will always evaluate to false.',
29+
15,
30+
],
31+
]);
32+
}
33+
34+
public function testBug141(): void
35+
{
36+
$this->analyse([__DIR__ . '/data/bug-141.php'], [
37+
[
38+
"Call to method PHPUnit\Framework\Assert::assertEmpty() with non-empty-array<'0.6.0'|'1.0.0'|'1.0.x-dev'|'1.1.x-dev'|'9999999-dev'|'dev-feature-b', true> will always evaluate to false.",
39+
23,
40+
],
41+
]);
42+
}
43+
44+
/**
45+
* @return string[]
46+
*/
47+
public static function getAdditionalConfigFiles(): array
48+
{
49+
return [
50+
__DIR__ . '/../../../extension.neon',
51+
__DIR__ . '/../../../vendor/phpstan/phpstan-strict-rules/rules.neon',
52+
];
53+
}
54+
55+
}

‎tests/Rules/PHPUnit/data/bug-141.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Bug141;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class Foo extends TestCase
8+
{
9+
10+
/**
11+
* @param array<'0.6.0'|'1.0.0'|'1.0.x-dev'|'1.1.x-dev'|'9999999-dev'|'dev-feature-b', true> $a
12+
*/
13+
public function doFoo(array $a): void
14+
{
15+
$this->assertEmpty($a);
16+
}
17+
18+
/**
19+
* @param non-empty-array<'0.6.0'|'1.0.0'|'1.0.x-dev'|'1.1.x-dev'|'9999999-dev'|'dev-feature-b', true> $a
20+
*/
21+
public function doBar(array $a): void
22+
{
23+
$this->assertEmpty($a);
24+
}
25+
26+
public function doBaz(): void
27+
{
28+
$expected = [
29+
'0.6.0' => true,
30+
'1.0.0' => true,
31+
'1.0.x-dev' => true,
32+
'1.1.x-dev' => true,
33+
'dev-feature-b' => true,
34+
'dev-feature/a-1.0-B' => true,
35+
'dev-master' => true,
36+
'9999999-dev' => true, // alias of dev-master
37+
];
38+
39+
/** @var array<string> */
40+
$packages = ['0.6.0', '1.0.0', '1'];
41+
42+
foreach ($packages as $version) {
43+
if (isset($expected[$version])) {
44+
unset($expected[$version]);
45+
} else {
46+
throw new \Exception('Unexpected version '.$version);
47+
}
48+
}
49+
50+
$this->assertEmpty($expected);
51+
}
52+
53+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace ImpossibleAssertMethodCall;
4+
5+
use Countable;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class Foo extends TestCase
9+
{
10+
11+
public function doFoo(Countable $c): void
12+
{
13+
$this->assertEmpty($c);
14+
$this->assertEmpty([]);
15+
$this->assertEmpty([1, 2, 3]);
16+
}
17+
18+
public function doBar(object $o): void
19+
{
20+
$this->assertEmpty($o);
21+
}
22+
23+
}

0 commit comments

Comments
(0)

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