Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
834 changes: 417 additions & 417 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Large diffs are not rendered by default.

248 changes: 124 additions & 124 deletions tests/PHPStan/Analyser/AnalyserTest.php

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testMethodIsInClassUsingTrait(): void
__DIR__ . '/traits/Foo.php',
__DIR__ . '/traits/FooTrait.php',
]);
$this->assertEmpty($errors);
self::assertEmpty($errors);
}

public function testMethodDoesNotExist(): void
Expand All @@ -40,14 +40,14 @@ public function testMethodDoesNotExist(): void
__DIR__ . '/traits/Bar.php',
__DIR__ . '/traits/FooTrait.php',
]);
$this->assertCount(1, $errors);
self::assertCount(1, $errors);
$error = $errors[0];
$this->assertSame('Call to an undefined method AnalyseTraits\Bar::doFoo().', $error->getMessage());
$this->assertSame(
self::assertSame('Call to an undefined method AnalyseTraits\Bar::doFoo().', $error->getMessage());
self::assertSame(
sprintf('%s (in context of class AnalyseTraits\Bar)', $this->fileHelper->normalizePath(__DIR__ . '/traits/FooTrait.php')),
$error->getFile(),
);
$this->assertSame(10, $error->getLine());
self::assertSame(10, $error->getLine());
}

public function testNestedTraits(): void
Expand All @@ -57,51 +57,51 @@ public function testNestedTraits(): void
__DIR__ . '/traits/NestedFooTrait.php',
__DIR__ . '/traits/FooTrait.php',
]);
$this->assertCount(2, $errors);
self::assertCount(2, $errors);
$firstError = $errors[0];
$this->assertSame('Call to an undefined method AnalyseTraits\NestedBar::doFoo().', $firstError->getMessage());
$this->assertSame(
self::assertSame('Call to an undefined method AnalyseTraits\NestedBar::doFoo().', $firstError->getMessage());
self::assertSame(
sprintf('%s (in context of class AnalyseTraits\NestedBar)', $this->fileHelper->normalizePath(__DIR__ . '/traits/FooTrait.php')),
$firstError->getFile(),
);
$this->assertSame(10, $firstError->getLine());
self::assertSame(10, $firstError->getLine());

$secondError = $errors[1];
$this->assertSame('Call to an undefined method AnalyseTraits\NestedBar::doNestedFoo().', $secondError->getMessage());
$this->assertSame(
self::assertSame('Call to an undefined method AnalyseTraits\NestedBar::doNestedFoo().', $secondError->getMessage());
self::assertSame(
sprintf('%s (in context of class AnalyseTraits\NestedBar)', $this->fileHelper->normalizePath(__DIR__ . '/traits/NestedFooTrait.php')),
$secondError->getFile(),
);
$this->assertSame(12, $secondError->getLine());
self::assertSame(12, $secondError->getLine());
}

public function testTraitsAreNotAnalysedDirectly(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/FooTrait.php']);
$this->assertEmpty($errors);
self::assertEmpty($errors);
$errors = $this->runAnalyse([__DIR__ . '/traits/NestedFooTrait.php']);
$this->assertEmpty($errors);
self::assertEmpty($errors);
}

public function testClassAndTraitInTheSameFile(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/classAndTrait.php']);
$this->assertEmpty($errors);
self::assertEmpty($errors);
}

public function testTraitMethodAlias(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/trait-aliases.php']);
$this->assertEmpty($errors);
self::assertEmpty($errors);
}

public function testFindErrorsInTrait(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/trait-error.php']);
$this->assertCount(3, $errors);
$this->assertSame('Undefined variable: $undefined', $errors[0]->getMessage());
$this->assertSame('Call to an undefined method TraitErrors\MyClass::undefined().', $errors[1]->getMessage());
$this->assertSame('Undefined variable: $undefined', $errors[2]->getMessage());
self::assertCount(3, $errors);
self::assertSame('Undefined variable: $undefined', $errors[0]->getMessage());
self::assertSame('Call to an undefined method TraitErrors\MyClass::undefined().', $errors[1]->getMessage());
self::assertSame('Undefined variable: $undefined', $errors[2]->getMessage());
}

public function testTraitInAnonymousClass(): void
Expand All @@ -112,56 +112,56 @@ public function testTraitInAnonymousClass(): void
__DIR__ . '/traits/TraitWithTypeSpecification.php',
],
);
$this->assertCount(1, $errors);
$this->assertStringContainsString('Access to an undefined property', $errors[0]->getMessage());
$this->assertSame(18, $errors[0]->getLine());
self::assertCount(1, $errors);
self::assertStringContainsString('Access to an undefined property', $errors[0]->getMessage());
self::assertSame(18, $errors[0]->getLine());
}

public function testDuplicateMethodDefinition(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/duplicateMethod/Lesson.php']);
$this->assertNoErrors($errors);
self::assertNoErrors($errors);
}

public function testWrongPropertyType(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/wrongProperty/Foo.php']);
$this->assertCount(2, $errors);
$this->assertSame(15, $errors[0]->getLine());
$this->assertSame(
self::assertCount(2, $errors);
self::assertSame(15, $errors[0]->getLine());
self::assertSame(
$this->fileHelper->normalizePath(__DIR__ . '/traits/wrongProperty/Foo.php'),
$errors[0]->getFile(),
);
$this->assertSame('Property TraitsWrongProperty\Foo::$id (int) does not accept string.', $errors[0]->getMessage());
self::assertSame('Property TraitsWrongProperty\Foo::$id (int) does not accept string.', $errors[0]->getMessage());

$this->assertSame(17, $errors[1]->getLine());
$this->assertSame(
self::assertSame(17, $errors[1]->getLine());
self::assertSame(
$this->fileHelper->normalizePath(__DIR__ . '/traits/wrongProperty/Foo.php'),
$errors[1]->getFile(),
);
$this->assertSame('Property TraitsWrongProperty\Foo::$bar (Ipsum) does not accept int.', $errors[1]->getMessage());
self::assertSame('Property TraitsWrongProperty\Foo::$bar (Ipsum) does not accept int.', $errors[1]->getMessage());
}

public function testReturnThis(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/returnThis/Bar.php']);
$this->assertCount(2, $errors);
$this->assertSame(10, $errors[0]->getLine());
$this->assertSame('Call to an undefined method TraitsReturnThis\Foo::doFoo().', $errors[0]->getMessage());
$this->assertSame(11, $errors[1]->getLine());
$this->assertSame('Call to an undefined method TraitsReturnThis\Foo::doFoo().', $errors[1]->getMessage());
self::assertCount(2, $errors);
self::assertSame(10, $errors[0]->getLine());
self::assertSame('Call to an undefined method TraitsReturnThis\Foo::doFoo().', $errors[0]->getMessage());
self::assertSame(11, $errors[1]->getLine());
self::assertSame('Call to an undefined method TraitsReturnThis\Foo::doFoo().', $errors[1]->getMessage());
}

public function testTraitInEval(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/TraitInEvalUse.php']);
$this->assertNoErrors($errors);
self::assertNoErrors($errors);
}

public function testParameterNotFoundCrash(): void
{
$errors = $this->runAnalyse([__DIR__ . '/traits/parameter-not-found.php']);
$this->assertNoErrors($errors);
self::assertNoErrors($errors);
}

public function testMissingReturnInAbstractTraitMethod(): void
Expand All @@ -170,7 +170,7 @@ public function testMissingReturnInAbstractTraitMethod(): void
__DIR__ . '/traits/TraitWithAbstractMethod.php',
__DIR__ . '/traits/ClassImplementingTraitWithAbstractMethod.php',
]);
$this->assertNoErrors($errors);
self::assertNoErrors($errors);
}

#[RequiresPhp('>= 8.1')]
Expand All @@ -180,24 +180,24 @@ public function testUnititializedReadonlyPropertyAccessedInTrait(): void
__DIR__ . '/traits/uninitializedProperty/FooClass.php',
__DIR__ . '/traits/uninitializedProperty/FooTrait.php',
]);
$this->assertCount(3, $errors);
self::assertCount(3, $errors);
usort($errors, static fn (Error $a, Error $b) => $a->getLine() <=> $b->getLine());
$expectedFile = sprintf('%s (in context of class TraitsUnititializedProperty\FooClass)', $this->fileHelper->normalizePath(__DIR__ . '/traits/uninitializedProperty/FooTrait.php'));

$error = $errors[0];
$this->assertSame('Access to an uninitialized readonly property TraitsUnititializedProperty\FooClass::$x.', $error->getMessage());
$this->assertSame(15, $error->getLine());
$this->assertSame($expectedFile, $error->getFile());
self::assertSame('Access to an uninitialized readonly property TraitsUnititializedProperty\FooClass::$x.', $error->getMessage());
self::assertSame(15, $error->getLine());
self::assertSame($expectedFile, $error->getFile());

$error = $errors[1];
$this->assertSame('Access to an uninitialized @readonly property TraitsUnititializedProperty\FooClass::$y.', $error->getMessage());
$this->assertSame(16, $error->getLine());
$this->assertSame($expectedFile, $error->getFile());
self::assertSame('Access to an uninitialized @readonly property TraitsUnititializedProperty\FooClass::$y.', $error->getMessage());
self::assertSame(16, $error->getLine());
self::assertSame($expectedFile, $error->getFile());

$error = $errors[2];
$this->assertSame('Access to an uninitialized property TraitsUnititializedProperty\FooClass::$z.', $error->getMessage());
$this->assertSame(17, $error->getLine());
$this->assertSame($expectedFile, $error->getFile());
self::assertSame('Access to an uninitialized property TraitsUnititializedProperty\FooClass::$z.', $error->getMessage());
self::assertSame(17, $error->getLine());
self::assertSame($expectedFile, $error->getFile());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class AnalyserWithCheckDynamicPropertiesTest extends PHPStanTestCase
public function testBug13529(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-13529.php');
$this->assertCount(1, $errors);
$this->assertSame('Access to an undefined property object::$bar.', $errors[0]->getMessage());
$this->assertSame(8, $errors[0]->getLine());
self::assertCount(1, $errors);
self::assertSame('Access to an undefined property object::$bar.', $errors[0]->getMessage());
self::assertSame(8, $errors[0]->getLine());
}

/**
Expand All @@ -32,7 +32,7 @@ private function runAnalyse(string $file): array
true,
)->getErrors();
foreach ($errors as $error) {
$this->assertSame($file, $error->getFilePath());
self::assertSame($file, $error->getFilePath());
}

return $errors;
Expand Down
48 changes: 24 additions & 24 deletions tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public function testArgumentReorderAllNamed(): void
$funcCall = new FuncCall($funcName, $args);

$funcCall = ArgumentsNormalizer::reorderFuncArguments($parameterAcceptor, $funcCall);
$this->assertNotNull($funcCall);
self::assertNotNull($funcCall);
$reorderedArgs = $funcCall->getArgs();
$this->assertCount(2, $reorderedArgs);
self::assertCount(2, $reorderedArgs);

$this->assertNull($reorderedArgs[0]->name, 'named-arg turned into regular numeric arg');
$this->assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at the right position');
self::assertNull($reorderedArgs[0]->name, 'named-arg turned into regular numeric arg');
self::assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at the right position');

$this->assertNull($reorderedArgs[1]->name, 'named-arg turned into regular numeric arg');
$this->assertInstanceOf(LNumber::class, $reorderedArgs[1]->value, 'flags-arg at the right position');
$this->assertSame(0, $reorderedArgs[1]->value->value);
self::assertNull($reorderedArgs[1]->name, 'named-arg turned into regular numeric arg');
self::assertInstanceOf(LNumber::class, $reorderedArgs[1]->value, 'flags-arg at the right position');
self::assertSame(0, $reorderedArgs[1]->value->value);
}

/**
Expand Down Expand Up @@ -84,21 +84,21 @@ public function testArgumentReorderAllNamedWithSkipped(): void
$funcCall = new FuncCall($funcName, $args);

$funcCall = ArgumentsNormalizer::reorderFuncArguments($parameterAcceptor, $funcCall);
$this->assertNotNull($funcCall);
self::assertNotNull($funcCall);
$reorderedArgs = $funcCall->getArgs();
$this->assertCount(3, $reorderedArgs);
self::assertCount(3, $reorderedArgs);

$this->assertNull($reorderedArgs[0]->name, 'named-arg turned into regular numeric arg');
$this->assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at the right position');
self::assertNull($reorderedArgs[0]->name, 'named-arg turned into regular numeric arg');
self::assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at the right position');

$this->assertNull($reorderedArgs[1]->name, 'named-arg turned into regular numeric arg');
$this->assertInstanceOf(TypeExpr::class, $reorderedArgs[1]->value, 'flags-arg at the right position');
$this->assertInstanceOf(ConstantIntegerType::class, $reorderedArgs[1]->value->getExprType());
$this->assertSame(0, $reorderedArgs[1]->value->getExprType()->getValue(), 'flags-arg with default value');
self::assertNull($reorderedArgs[1]->name, 'named-arg turned into regular numeric arg');
self::assertInstanceOf(TypeExpr::class, $reorderedArgs[1]->value, 'flags-arg at the right position');
self::assertInstanceOf(ConstantIntegerType::class, $reorderedArgs[1]->value->getExprType());
self::assertSame(0, $reorderedArgs[1]->value->getExprType()->getValue(), 'flags-arg with default value');

$this->assertNull($reorderedArgs[2]->name, 'named-arg turned into regular numeric arg');
$this->assertInstanceOf(LNumber::class, $reorderedArgs[2]->value, 'depth-arg at the right position');
$this->assertSame(128, $reorderedArgs[2]->value->value);
self::assertNull($reorderedArgs[2]->name, 'named-arg turned into regular numeric arg');
self::assertInstanceOf(LNumber::class, $reorderedArgs[2]->value, 'depth-arg at the right position');
self::assertSame(128, $reorderedArgs[2]->value->value);
}

#[RequiresPhp('>= 8.0')]
Expand All @@ -120,7 +120,7 @@ public function testMissingRequiredParameter(): void
];
$funcCall = new FuncCall($funcName, $args);

$this->assertNull(ArgumentsNormalizer::reorderFuncArguments($parameterAcceptor, $funcCall));
self::assertNull(ArgumentsNormalizer::reorderFuncArguments($parameterAcceptor, $funcCall));
}

public function testLeaveRegularCallAsIs(): void
Expand All @@ -144,13 +144,13 @@ public function testLeaveRegularCallAsIs(): void
$funcCall = new FuncCall($funcName, $args);

$funcCall = ArgumentsNormalizer::reorderFuncArguments($parameterAcceptor, $funcCall);
$this->assertNotNull($funcCall);
self::assertNotNull($funcCall);
$reorderedArgs = $funcCall->getArgs();
$this->assertCount(2, $reorderedArgs);
self::assertCount(2, $reorderedArgs);

$this->assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at unchanged position');
$this->assertInstanceOf(LNumber::class, $reorderedArgs[1]->value, 'flags-arg at unchanged position');
$this->assertSame(0, $reorderedArgs[1]->value->value);
self::assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at unchanged position');
self::assertInstanceOf(LNumber::class, $reorderedArgs[1]->value, 'flags-arg at unchanged position');
self::assertSame(0, $reorderedArgs[1]->value->value);
}

}
12 changes: 6 additions & 6 deletions tests/PHPStan/Analyser/ArgumentsNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ public function testReorderValid(
),
new FuncCall(new Name('foo'), $arguments),
);
$this->assertNotNull($normalized);
self::assertNotNull($normalized);

$actualArguments = $normalized->getArgs();
$this->assertCount(count($expectedArgumentTypes), $actualArguments);
self::assertCount(count($expectedArgumentTypes), $actualArguments);
foreach ($actualArguments as $i => $actualArgument) {
$this->assertNull($actualArgument->name);
self::assertNull($actualArgument->name);
$value = $actualArgument->value;
$this->assertInstanceOf(TypeExpr::class, $value);
$this->assertSame(
self::assertInstanceOf(TypeExpr::class, $value);
self::assertSame(
$expectedArgumentTypes[$i]->describe(VerbosityLevel::precise()),
$value->getExprType()->describe(VerbosityLevel::precise()),
);
Expand Down Expand Up @@ -362,7 +362,7 @@ public function testReorderInvalid(
),
new FuncCall(new Name('foo'), $arguments),
);
$this->assertNull($normalized);
self::assertNull($normalized);
}

}
12 changes: 6 additions & 6 deletions tests/PHPStan/Analyser/Bug13813IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ public function testBug13813(): void
} finally {
error_reporting($oldReporting);
}
$this->assertCount(2, $analyzerResult->getAllPhpErrors());
$this->assertCount(2, $analyzerResult->getFilteredPhpErrors());
self::assertCount(2, $analyzerResult->getAllPhpErrors());
self::assertCount(2, $analyzerResult->getFilteredPhpErrors());

if (PHP_VERSION_ID >= 80000) {
$this->assertSame(
self::assertSame(
'Warning: Undefined variable $x',
$analyzerResult->getAllPhpErrors()[0]->getMessage(),
);
$this->assertSame(
self::assertSame(
'Warning: Undefined variable $x',
$analyzerResult->getAllPhpErrors()[1]->getMessage(),
);
} else {
$this->assertSame(
self::assertSame(
'Notice: Undefined variable: x',
$analyzerResult->getAllPhpErrors()[0]->getMessage(),
);
$this->assertSame(
self::assertSame(
'Notice: Undefined variable: x',
$analyzerResult->getAllPhpErrors()[1]->getMessage(),
);
Expand Down
Loading
Loading