Skip to content

Commit 1b71b51

Browse files
committed
Use Stubs instead of Mocks
No expectations were configured for the mock object for PHPStan\Analyser\Scope. You should refactor your test code and use a test stub instead.
1 parent c74f5fa commit 1b71b51

12 files changed

+21
-20
lines changed

tests/PHPStan/Command/AnalyseApplicationIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function runPath(string $path, int $expectedStatusCode): string
6262

6363
$symfonyOutput = new SymfonyOutput(
6464
$output,
65-
new \PHPStan\Command\Symfony\SymfonyStyle(new SymfonyStyle($this->createMock(InputInterface::class), $output)),
65+
new \PHPStan\Command\Symfony\SymfonyStyle(new SymfonyStyle($this->createStub(InputInterface::class), $output)),
6666
);
6767

6868
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), __DIR__, [], DIRECTORY_SEPARATOR);
@@ -88,7 +88,7 @@ private function runPath(string $path, int $expectedStatusCode): string
8888
null,
8989
null,
9090
null,
91-
$this->createMock(InputInterface::class),
91+
$this->createStub(InputInterface::class),
9292
);
9393
$statusCode = $errorFormatter->formatErrors($analysisResult, $symfonyOutput);
9494

tests/PHPStan/Parser/CachedParserTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Testing\PHPStanTestCase;
1111
use PHPUnit\Framework\Attributes\DataProvider;
1212
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\MockObject\Stub;
1314

1415
class CachedParserTest extends PHPStanTestCase
1516
{
@@ -21,7 +22,7 @@ public function testParseFileClearCache(
2122
): void
2223
{
2324
$parser = new CachedParser(
24-
$this->getParserMock(),
25+
$this->getParserStub(),
2526
$cachedNodesByStringCountMax,
2627
);
2728

@@ -62,19 +63,19 @@ public static function dataParseFileClearCache(): Generator
6263
];
6364
}
6465

65-
private function getParserMock(): Parser&MockObject
66+
private function getParserStub(): Parser&Stub
6667
{
67-
$mock = $this->createMock(Parser::class);
68+
$mock = $this->createStub(Parser::class);
6869

69-
$mock->method('parseFile')->willReturn([$this->getPhpParserNodeMock()]);
70-
$mock->method('parseString')->willReturn([$this->getPhpParserNodeMock()]);
70+
$mock->method('parseFile')->willReturn([$this->getPhpParserNodeStub()]);
71+
$mock->method('parseString')->willReturn([$this->getPhpParserNodeStub()]);
7172

7273
return $mock;
7374
}
7475

75-
private function getPhpParserNodeMock(): Node&MockObject
76+
private function getPhpParserNodeStub(): Node&Stub
7677
{
77-
return $this->createMock(Node::class);
78+
return $this->createStub(Node::class);
7879
}
7980

8081
public function testParseTheSameFileWithDifferentMethod(): void

tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ public function testMethods(string $className, array $methods): void
966966
{
967967
$reflectionProvider = self::createReflectionProvider();
968968
$class = $reflectionProvider->getClass($className);
969-
$scope = $this->createMock(Scope::class);
969+
$scope = $this->createStub(Scope::class);
970970
$scope->method('isInClass')->willReturn(true);
971971
$scope->method('getClassReflection')->willReturn($class);
972972
$scope->method('canCallMethod')->willReturn(true);

tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function testProperties(string $className, array $properties): void
280280
{
281281
$reflectionProvider = self::createReflectionProvider();
282282
$class = $reflectionProvider->getClass($className);
283-
$scope = $this->createMock(Scope::class);
283+
$scope = $this->createStub(Scope::class);
284284
$scope->method('isInClass')->willReturn(true);
285285
$scope->method('getClassReflection')->willReturn($class);
286286
$scope->method('canAccessProperty')->willReturn(true);

tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testDeprecatedAnnotations(bool $deprecated, string $className, ?
101101
{
102102
$reflectionProvider = self::createReflectionProvider();
103103
$class = $reflectionProvider->getClass($className);
104-
$scope = $this->createMock(Scope::class);
104+
$scope = $this->createStub(Scope::class);
105105
$scope->method('isInClass')->willReturn(true);
106106
$scope->method('getClassReflection')->willReturn($class);
107107
$scope->method('canAccessProperty')->willReturn(true);

tests/PHPStan/Reflection/Annotations/FinalAnnotationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testFinalAnnotations(bool $final, string $className, array $fina
4545
{
4646
$reflectionProvider = self::createReflectionProvider();
4747
$class = $reflectionProvider->getClass($className);
48-
$scope = $this->createMock(Scope::class);
48+
$scope = $this->createStub(Scope::class);
4949
$scope->method('isInClass')->willReturn(true);
5050
$scope->method('getClassReflection')->willReturn($class);
5151
$scope->method('canAccessProperty')->willReturn(true);

tests/PHPStan/Reflection/Annotations/InternalAnnotationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testInternalAnnotations(bool $internal, string $className, array
126126
{
127127
$reflectionProvider = self::createReflectionProvider();
128128
$class = $reflectionProvider->getClass($className);
129-
$scope = $this->createMock(Scope::class);
129+
$scope = $this->createStub(Scope::class);
130130
$scope->method('isInClass')->willReturn(true);
131131
$scope->method('getClassReflection')->willReturn($class);
132132
$scope->method('canAccessProperty')->willReturn(true);

tests/PHPStan/Reflection/Annotations/ThrowsAnnotationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testThrowsAnnotations(string $className, array $throwsAnnotation
7676
{
7777
$reflectionProvider = self::createReflectionProvider();
7878
$class = $reflectionProvider->getClass($className);
79-
$scope = $this->createMock(Scope::class);
79+
$scope = $this->createStub(Scope::class);
8080

8181
foreach ($throwsAnnotations as $methodName => $type) {
8282
$methodAnnotation = $class->getMethod($methodName, $scope);

tests/PHPStan/Reflection/FunctionReflectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testMethodHasPhpdoc(string $className, string $methodName, ?stri
119119
{
120120
$reflectionProvider = self::createReflectionProvider();
121121
$class = $reflectionProvider->getClass($className);
122-
$scope = $this->createMock(Scope::class);
122+
$scope = $this->createStub(Scope::class);
123123
$scope->method('isInClass')->willReturn(true);
124124
$scope->method('getClassReflection')->willReturn($class);
125125
$scope->method('canAccessProperty')->willReturn(true);
@@ -180,7 +180,7 @@ public function testMethodReturnsByReference(string $className, string $methodNa
180180
{
181181
$reflectionProvider = self::createReflectionProvider();
182182
$class = $reflectionProvider->getClass($className);
183-
$scope = $this->createMock(Scope::class);
183+
$scope = $this->createStub(Scope::class);
184184
$scope->method('isInClass')->willReturn(true);
185185
$scope->method('getClassReflection')->willReturn($class);
186186
$scope->method('canAccessProperty')->willReturn(true);

tests/PHPStan/Reflection/Type/IntersectionTypeMethodReflectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testMultipleDeprecationsAreJoined(): void
3838

3939
private function createDeprecatedMethod(TrinaryLogic $deprecated, ?string $deprecationText): ExtendedMethodReflection
4040
{
41-
$method = $this->createMock(ExtendedMethodReflection::class);
41+
$method = $this->createStub(ExtendedMethodReflection::class);
4242
$method->method('isDeprecated')->willReturn($deprecated);
4343
$method->method('getDeprecatedDescription')->willReturn($deprecationText);
4444
return $method;

0 commit comments

Comments
 (0)