Skip to content

Commit afdcf35

Browse files
authored
Use stricter assertions in tests (#6640)
1 parent 5bbd3da commit afdcf35

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

‎composer.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/PHPStan/Analyser/AnalyserIntegrationTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,20 +1693,20 @@ public function testBug14550(): void
16931693
{
16941694
// crash
16951695
$errors = $this->runAnalyse(__DIR__ . '/data/bug-14550.php');
1696-
$this->assertNotEmpty($errors);
1696+
$this->assertNotCount(0, $errors);
16971697
}
16981698

16991699
public function testBug14596(): void
17001700
{
17011701
// crash
17021702
$errors = $this->runAnalyse(__DIR__ . '/data/bug-14596.php');
1703-
$this->assertNotEmpty($errors);
1703+
$this->assertNotCount(0, $errors);
17041704
}
17051705

17061706
public function testBug9172(): void
17071707
{
17081708
$errors = $this->runAnalyse(__DIR__ . '/data/bug-9172.php');
1709-
$this->assertNotEmpty($errors);
1709+
$this->assertNotCount(0, $errors);
17101710
}
17111711

17121712
#[RequiresPhp('>= 8.1.0')]

‎tests/PHPStan/Analyser/AnalyserTest.php‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,31 @@ public function testReturnErrorIfIgnoredMessagesDoesNotOccur(): void
4949
public function testDoNotReturnErrorIfIgnoredMessagesDoesNotOccurWithReportUnmatchedIgnoredErrorsOff(): void
5050
{
5151
$result = $this->runAnalyser(['#Unknown error#'], false, __DIR__ . '/data/empty/empty.php', false);
52-
$this->assertEmpty($result);
52+
$this->assertCount(0, $result);
5353
}
5454

5555
public function testDoNotReturnErrorIfIgnoredMessagesDoNotOccurWhileAnalysingIndividualFiles(): void
5656
{
5757
$result = $this->runAnalyser(['#Unknown error#'], true, __DIR__ . '/data/empty/empty.php', true);
58-
$this->assertEmpty($result);
58+
$this->assertCount(0, $result);
5959
}
6060

6161
public function testFileWithAnIgnoredError(): void
6262
{
6363
$result = $this->runAnalyser(['#Fail\.#'], true, __DIR__ . '/data/bootstrap-error.php', false);
64-
$this->assertEmpty($result);
64+
$this->assertCount(0, $result);
6565
}
6666

6767
public function testFileWithAnIgnoredErrorMessage(): void
6868
{
6969
$result = $this->runAnalyser([['message' => '#Fail\.#']], true, __DIR__ . '/data/bootstrap-error.php', false);
70-
$this->assertEmpty($result);
70+
$this->assertCount(0, $result);
7171
}
7272

7373
public function testFileWithAnIgnoredErrorRawMessage(): void
7474
{
7575
$result = $this->runAnalyser([['rawMessage' => 'Fail.']], true, __DIR__ . '/data/bootstrap-error.php', false);
76-
$this->assertEmpty($result);
76+
$this->assertCount(0, $result);
7777
}
7878

7979
public function testFileWithAnIgnoredErrorMessageAndWrongIdentifier(): void
@@ -109,19 +109,19 @@ public function testFileWithAnIgnoredWrongIdentifier(): void
109109
public function testFileWithAnIgnoredErrorMessageAndCorrectIdentifier(): void
110110
{
111111
$result = $this->runAnalyser([['message' => '#Fail\.#', 'identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false);
112-
$this->assertEmpty($result);
112+
$this->assertCount(0, $result);
113113
}
114114

115115
public function testFileWithAnIgnoredErrorRawMessageAndCorrectIdentifier(): void
116116
{
117117
$result = $this->runAnalyser([['rawMessage' => 'Fail.', 'identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false);
118-
$this->assertEmpty($result);
118+
$this->assertCount(0, $result);
119119
}
120120

121121
public function testFileWithAnIgnoredErrorIdentifier(): void
122122
{
123123
$result = $this->runAnalyser([['identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false);
124-
$this->assertEmpty($result);
124+
$this->assertCount(0, $result);
125125
}
126126

127127
public function testFileWithAnIgnoredErrorMessages(): void

‎tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testMethodIsInClassUsingTrait(): void
3232
__DIR__ . '/traits/Foo.php',
3333
__DIR__ . '/traits/FooTrait.php',
3434
]);
35-
$this->assertEmpty($errors);
35+
$this->assertCount(0, $errors);
3636
}
3737

3838
public function testMethodDoesNotExist(): void
@@ -95,21 +95,21 @@ public function testNestedTraits(): void
9595
public function testTraitsAreNotAnalysedDirectly(): void
9696
{
9797
$errors = $this->runAnalyse([__DIR__ . '/traits/FooTrait.php']);
98-
$this->assertEmpty($errors);
98+
$this->assertCount(0, $errors);
9999
$errors = $this->runAnalyse([__DIR__ . '/traits/NestedFooTrait.php']);
100-
$this->assertEmpty($errors);
100+
$this->assertCount(0, $errors);
101101
}
102102

103103
public function testClassAndTraitInTheSameFile(): void
104104
{
105105
$errors = $this->runAnalyse([__DIR__ . '/traits/classAndTrait.php']);
106-
$this->assertEmpty($errors);
106+
$this->assertCount(0, $errors);
107107
}
108108

109109
public function testTraitMethodAlias(): void
110110
{
111111
$errors = $this->runAnalyse([__DIR__ . '/traits/trait-aliases.php']);
112-
$this->assertEmpty($errors);
112+
$this->assertCount(0, $errors);
113113
}
114114

115115
public function testFindErrorsInTrait(): void

‎tests/PHPStan/Reflection/ConstantToFunctionParameterMapTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testMapIsValid(): void
4545

4646
$methodReflection = $classReflection->getNativeMethod($methodName);
4747
$variants = $methodReflection->getVariants();
48-
$this->assertNotEmpty($variants, sprintf('Method %s has no variants.', $entry));
48+
$this->assertNotCount(0, $variants, sprintf('Method %s has no variants.', $entry));
4949

5050
$reflectionParameters = $variants[0]->getParameters();
5151
} else {
@@ -59,7 +59,7 @@ public function testMapIsValid(): void
5959

6060
$functionReflection = $reflectionProvider->getFunction($nameNode, null);
6161
$variants = $functionReflection->getVariants();
62-
$this->assertNotEmpty($variants, sprintf('Function %s() has no variants.', $entry));
62+
$this->assertNotCount(0, $variants, sprintf('Function %s() has no variants.', $entry));
6363

6464
$reflectionParameters = $variants[0]->getParameters();
6565
}
@@ -87,7 +87,7 @@ public function testMapIsValid(): void
8787
$this->assertContains($config['type'], ['single', 'bitmask'], sprintf('Invalid type "%s" for %s($%s).', $config['type'], $entry, $parameterName));
8888
$this->assertArrayHasKey('constants', $config, sprintf('Missing "constants" key for %s($%s).', $entry, $parameterName));
8989
$this->assertIsArray($config['constants'], sprintf('Constants for %s($%s) must be an array.', $entry, $parameterName));
90-
$this->assertNotEmpty($config['constants'], sprintf('Constants for %s($%s) must not be empty.', $entry, $parameterName));
90+
$this->assertNotCount(0, $config['constants'], sprintf('Constants for %s($%s) must not be empty.', $entry, $parameterName));
9191

9292
foreach ($config['constants'] as $constantName) {
9393
$this->assertIsString($constantName, sprintf('Constant name for %s($%s) must be a string.', $entry, $parameterName));

0 commit comments

Comments
 (0)