Skip to content

Commit df9d36f

Browse files
committed
Check tests with phpstan
1 parent 78287ac commit df9d36f

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"phpstan/phpstan": "2.1.0",
1212
"phpunit/phpunit": "^9.5",
1313
"phpstan/extension-installer": "^1.0",
14-
"phpstan/phpstan-strict-rules": "^2.0"
14+
"phpstan/phpstan-strict-rules": "^2.0",
15+
"phpstan/phpstan-phpunit": "^2.0"
1516
},
1617
"license": "LGPL-3.0",
1718
"autoload": {

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
includes:
2+
- tests/phpstan/configs/expected-test-errors.neon
23
- tests/phpstan/configs/impossible-mixed.neon
34
- tests/phpstan/configs/phpstan-bugs.neon
45

@@ -7,3 +8,4 @@ parameters:
78
treatPhpDocTypesAsCertain: false
89
paths:
910
- src
11+
- tests
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Expression "clone \$tag" on a separate line does not do anything\.$#'
5+
identifier: expr.resultUnused
6+
count: 1
7+
path: ../../phpunit/tag/CompoundTagTest.php
8+
9+
-
10+
message: '#^Expression "clone \$tag" on a separate line does not do anything\.$#'
11+
identifier: expr.resultUnused
12+
count: 1
13+
path: ../../phpunit/tag/ListTagTest.php

tests/phpstan/configs/phpstan-bugs.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ parameters:
1717
identifier: assign.propertyType
1818
count: 1
1919
path: ../../../src/tag/ListTag.php
20+
21+
-
22+
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
23+
identifier: function.alreadyNarrowedType
24+
count: 1
25+
path: ../../phpunit/tag/CompoundTagTest.php

tests/phpunit/JsonNbtParserTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ public function testParseGarbage() : void{
5656

5757
public function testEmptyCompound() : void{
5858
$tag = JsonNbtParser::parseJson("{}");
59-
self::assertNotNull($tag);
6059
self::assertCount(0, $tag);
6160
}
6261

6362
public function testEmptyList() : void{
6463
$tag = JsonNbtParser::parseJson("{TestList:[]}");
65-
self::assertNotNull($tag);
6664
$list = $tag->getTag("TestList");
6765
self::assertTrue($list instanceof ListTag);
6866
self::assertCount(0, $list);

tests/phpunit/tag/CompoundTagTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ public function testEquals() : void{
129129

130130
self::assertTrue($tag1->equals($tag2));
131131

132-
$tag2->getCompoundTag("child9")->setFloat("hello", 1.0);
132+
$child9 = $tag2->getCompoundTag("child9");
133+
self::assertNotNull($child9);
134+
$child9->setFloat("hello", 1.0);
133135
self::assertNotTrue($tag1->equals($tag2));
134136
}
135137

0 commit comments

Comments
 (0)