Skip to content

Commit 38a1d56

Browse files
committed
Use createReflectionProvider() instead of createBroker() in tests
1 parent 10852a0 commit 38a1d56

23 files changed

+78
-100
lines changed

src/Testing/RuleTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ private function getAnalyser(): Analyser
4444
$this->getRule(),
4545
]);
4646

47-
$broker = $this->createBroker();
47+
$reflectionProvider = $this->createReflectionProvider();
4848
$typeSpecifier = $this->getTypeSpecifier();
4949
$nodeScopeResolver = new NodeScopeResolver(
50-
$broker,
50+
$reflectionProvider,
5151
self::getReflectors()[0],
5252
$this->getClassReflectionExtensionRegistryProvider(),
5353
$this->getParser(),
@@ -65,7 +65,7 @@ private function getAnalyser(): Analyser
6565
true
6666
);
6767
$fileAnalyser = new FileAnalyser(
68-
$this->createScopeFactory($broker, $typeSpecifier),
68+
$this->createScopeFactory($reflectionProvider, $typeSpecifier),
6969
$nodeScopeResolver,
7070
$this->getParser(),
7171
self::getContainer()->getByType(DependencyResolver::class),

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Bug4288\MyClass;
66
use Bug4713\Service;
7-
use PHPStan\Broker\Broker;
87
use PHPStan\File\FileHelper;
98
use PHPStan\Reflection\ParametersAcceptorSelector;
109
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
@@ -83,8 +82,8 @@ public function testExtendingKnownClassWithCheck(): void
8382
$errors = $this->runAnalyse(__DIR__ . '/data/extending-known-class-with-check.php');
8483
$this->assertCount(0, $errors);
8584

86-
$broker = self::getContainer()->getByType(Broker::class);
87-
$this->assertTrue($broker->hasClass(\ExtendingKnownClassWithCheck\Foo::class));
85+
$reflectionProvider = $this->createReflectionProvider();
86+
$this->assertTrue($reflectionProvider->hasClass(\ExtendingKnownClassWithCheck\Foo::class));
8887
}
8988

9089
public function testInfiniteRecursionWithCallable(): void
@@ -353,7 +352,7 @@ public function testBug4713(): void
353352
$this->assertCount(1, $errors);
354353
$this->assertSame('Method Bug4713\Service::createInstance() should return Bug4713\Service but returns object.', $errors[0]->getMessage());
355354

356-
$reflectionProvider = $this->createBroker();
355+
$reflectionProvider = $this->createReflectionProvider();
357356
$class = $reflectionProvider->getClass(Service::class);
358357
$parameter = ParametersAcceptorSelector::selectSingle($class->getNativeMethod('createInstance')->getVariants())->getParameters()[0];
359358
$defaultValue = $parameter->getDefaultValue();
@@ -366,7 +365,7 @@ public function testBug4288(): void
366365
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4288.php');
367366
$this->assertCount(0, $errors);
368367

369-
$reflectionProvider = $this->createBroker();
368+
$reflectionProvider = $this->createReflectionProvider();
370369
$class = $reflectionProvider->getClass(MyClass::class);
371370
$parameter = ParametersAcceptorSelector::selectSingle($class->getNativeMethod('paginate')->getVariants())->getParameters()[0];
372371
$defaultValue = $parameter->getDefaultValue();

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ private function createAnalyser(bool $reportUnmatchedIgnoredErrors): \PHPStan\An
482482
new AlwaysFailRule(),
483483
]);
484484

485-
$broker = $this->createBroker();
485+
$reflectionProvider = $this->createReflectionProvider();
486486
$printer = new \PhpParser\PrettyPrinter\Standard();
487487
$fileHelper = $this->getFileHelper();
488488

@@ -491,7 +491,7 @@ private function createAnalyser(bool $reportUnmatchedIgnoredErrors): \PHPStan\An
491491
$phpDocInheritanceResolver = new PhpDocInheritanceResolver($fileTypeMapper);
492492

493493
$nodeScopeResolver = new NodeScopeResolver(
494-
$broker,
494+
$reflectionProvider,
495495
self::getReflectors()[0],
496496
$this->getClassReflectionExtensionRegistryProvider(),
497497
$this->getParser(),
@@ -510,15 +510,15 @@ private function createAnalyser(bool $reportUnmatchedIgnoredErrors): \PHPStan\An
510510
);
511511
$lexer = new \PhpParser\Lexer(['usedAttributes' => ['comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos']]);
512512
$fileAnalyser = new FileAnalyser(
513-
$this->createScopeFactory($broker, $typeSpecifier),
513+
$this->createScopeFactory($reflectionProvider, $typeSpecifier),
514514
$nodeScopeResolver,
515515
new RichParser(
516516
new \PhpParser\Parser\Php7($lexer),
517517
new \PhpParser\NodeVisitor\NameResolver(),
518518
new NodeConnectingVisitor(),
519519
new StatementOrderVisitor()
520520
),
521-
new DependencyResolver($fileHelper, $broker, new ExportedNodeResolver($fileTypeMapper, $printer)),
521+
new DependencyResolver($fileHelper, $reflectionProvider, new ExportedNodeResolver($fileTypeMapper, $printer)),
522522
$reportUnmatchedIgnoredErrors
523523
);
524524

tests/PHPStan/Analyser/AnonymousClassNameRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class AnonymousClassNameRuleTest extends RuleTestCase
1010

1111
protected function getRule(): Rule
1212
{
13-
$broker = $this->createReflectionProvider();
14-
return new AnonymousClassNameRule($broker);
13+
$reflectionProvider = $this->createReflectionProvider();
14+
return new AnonymousClassNameRule($reflectionProvider);
1515
}
1616

1717
public function testRule(): void

tests/PHPStan/Analyser/TypeSpecifierTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class TypeSpecifierTest extends \PHPStan\Testing\PHPStanTestCase
4646

4747
protected function setUp(): void
4848
{
49-
$broker = $this->createBroker();
49+
$reflectionProvider = $this->createReflectionProvider();
5050
$this->printer = new \PhpParser\PrettyPrinter\Standard();
5151
$this->typeSpecifier = self::getContainer()->getService('typeSpecifier');
52-
$this->scope = $this->createScopeFactory($broker, $this->typeSpecifier)->create(ScopeContext::create(''));
53-
$this->scope = $this->scope->enterClass($broker->getClass('DateTime'));
52+
$this->scope = $this->createScopeFactory($reflectionProvider, $this->typeSpecifier)->create(ScopeContext::create(''));
53+
$this->scope = $this->scope->enterClass($reflectionProvider->getClass('DateTime'));
5454
$this->scope = $this->scope->assignVariable('bar', new ObjectType('Bar'));
5555
$this->scope = $this->scope->assignVariable('stringOrNull', new UnionType([new StringType(), new NullType()]));
5656
$this->scope = $this->scope->assignVariable('string', new StringType());

tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Reflection\Annotations;
44

55
use PHPStan\Analyser\Scope;
6-
use PHPStan\Broker\Broker;
76
use PHPStan\Reflection\ParametersAcceptorSelector;
87
use PHPStan\Reflection\PassedByReference;
98
use PHPStan\Reflection\Php\PhpMethodReflection;
@@ -957,9 +956,8 @@ public function dataMethods(): array
957956
*/
958957
public function testMethods(string $className, array $methods): void
959958
{
960-
/** @var Broker $broker */
961-
$broker = self::getContainer()->getByType(Broker::class);
962-
$class = $broker->getClass($className);
959+
$reflectionProvider = $this->createReflectionProvider();
960+
$class = $reflectionProvider->getClass($className);
963961
$scope = $this->createMock(Scope::class);
964962
$scope->method('isInClass')->willReturn(true);
965963
$scope->method('getClassReflection')->willReturn($class);
@@ -1020,8 +1018,8 @@ public function testMethods(string $className, array $methods): void
10201018

10211019
public function testOverridingNativeMethodsWithAnnotationsDoesNotBreakGetNativeMethod(): void
10221020
{
1023-
$broker = self::getContainer()->getByType(Broker::class);
1024-
$class = $broker->getClass(\AnnotationsMethods\Bar::class);
1021+
$reflectionProvider = $this->createReflectionProvider();
1022+
$class = $reflectionProvider->getClass(\AnnotationsMethods\Bar::class);
10251023
$this->assertTrue($class->hasNativeMethod('overridenMethodWithAnnotation'));
10261024
$this->assertInstanceOf(PhpMethodReflection::class, $class->getNativeMethod('overridenMethodWithAnnotation'));
10271025
}

tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Reflection\Annotations;
44

55
use PHPStan\Analyser\Scope;
6-
use PHPStan\Broker\Broker;
76
use PHPStan\Type\VerbosityLevel;
87

98
class AnnotationsPropertiesClassReflectionExtensionTest extends \PHPStan\Testing\PHPStanTestCase
@@ -216,9 +215,8 @@ public function dataProperties(): array
216215
*/
217216
public function testProperties(string $className, array $properties): void
218217
{
219-
/** @var Broker $broker */
220-
$broker = self::getContainer()->getByType(Broker::class);
221-
$class = $broker->getClass($className);
218+
$reflectionProvider = $this->createReflectionProvider();
219+
$class = $reflectionProvider->getClass($className);
222220
$scope = $this->createMock(Scope::class);
223221
$scope->method('isInClass')->willReturn(true);
224222
$scope->method('getClassReflection')->willReturn($class);
@@ -255,8 +253,8 @@ public function testProperties(string $className, array $properties): void
255253

256254
public function testOverridingNativePropertiesWithAnnotationsDoesNotBreakGetNativeProperty(): void
257255
{
258-
$broker = self::getContainer()->getByType(Broker::class);
259-
$class = $broker->getClass(\AnnotationsProperties\Bar::class);
256+
$reflectionProvider = $this->createReflectionProvider();
257+
$class = $reflectionProvider->getClass(\AnnotationsProperties\Bar::class);
260258
$this->assertTrue($class->hasNativeProperty('overridenPropertyWithAnnotation'));
261259
$this->assertSame('AnnotationsProperties\Foo', $class->getNativeProperty('overridenPropertyWithAnnotation')->getReadableType()->describe(VerbosityLevel::precise()));
262260
}

tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node\Name;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Broker\Broker;
87

98
class DeprecatedAnnotationsTest extends \PHPStan\Testing\PHPStanTestCase
109
{
@@ -84,9 +83,8 @@ public function dataDeprecatedAnnotations(): array
8483
*/
8584
public function testDeprecatedAnnotations(bool $deprecated, string $className, ?string $classDeprecation, array $deprecatedAnnotations): void
8685
{
87-
/** @var Broker $broker */
88-
$broker = self::getContainer()->getByType(Broker::class);
89-
$class = $broker->getClass($className);
86+
$reflectionProvider = $this->createReflectionProvider();
87+
$class = $reflectionProvider->getClass($className);
9088
$scope = $this->createMock(Scope::class);
9189
$scope->method('isInClass')->willReturn(true);
9290
$scope->method('getClassReflection')->willReturn($class);
@@ -118,21 +116,19 @@ public function testDeprecatedUserFunctions(): void
118116
{
119117
require_once __DIR__ . '/data/annotations-deprecated.php';
120118

121-
/** @var Broker $broker */
122-
$broker = self::getContainer()->getByType(Broker::class);
119+
$reflectionProvider = $this->createReflectionProvider();
123120

124-
$this->assertFalse($broker->getFunction(new Name\FullyQualified('DeprecatedAnnotations\foo'), null)->isDeprecated()->yes());
125-
$this->assertTrue($broker->getFunction(new Name\FullyQualified('DeprecatedAnnotations\deprecatedFoo'), null)->isDeprecated()->yes());
121+
$this->assertFalse($reflectionProvider->getFunction(new Name\FullyQualified('DeprecatedAnnotations\foo'), null)->isDeprecated()->yes());
122+
$this->assertTrue($reflectionProvider->getFunction(new Name\FullyQualified('DeprecatedAnnotations\deprecatedFoo'), null)->isDeprecated()->yes());
126123
}
127124

128125
public function testNonDeprecatedNativeFunctions(): void
129126
{
130-
/** @var Broker $broker */
131-
$broker = self::getContainer()->getByType(Broker::class);
127+
$reflectionProvider = $this->createReflectionProvider();
132128

133-
$this->assertFalse($broker->getFunction(new Name('str_replace'), null)->isDeprecated()->yes());
134-
$this->assertFalse($broker->getFunction(new Name('get_class'), null)->isDeprecated()->yes());
135-
$this->assertFalse($broker->getFunction(new Name('function_exists'), null)->isDeprecated()->yes());
129+
$this->assertFalse($reflectionProvider->getFunction(new Name('str_replace'), null)->isDeprecated()->yes());
130+
$this->assertFalse($reflectionProvider->getFunction(new Name('get_class'), null)->isDeprecated()->yes());
131+
$this->assertFalse($reflectionProvider->getFunction(new Name('function_exists'), null)->isDeprecated()->yes());
136132
}
137133

138134
}

tests/PHPStan/Reflection/Annotations/FinalAnnotationsTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node\Name;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Broker\Broker;
87

98
class FinalAnnotationsTest extends \PHPStan\Testing\PHPStanTestCase
109
{
@@ -43,9 +42,8 @@ public function dataFinalAnnotations(): array
4342
*/
4443
public function testFinalAnnotations(bool $final, string $className, array $finalAnnotations): void
4544
{
46-
/** @var Broker $broker */
47-
$broker = self::getContainer()->getByType(Broker::class);
48-
$class = $broker->getClass($className);
45+
$reflectionProvider = $this->createReflectionProvider();
46+
$class = $reflectionProvider->getClass($className);
4947
$scope = $this->createMock(Scope::class);
5048
$scope->method('isInClass')->willReturn(true);
5149
$scope->method('getClassReflection')->willReturn($class);
@@ -63,11 +61,10 @@ public function testFinalUserFunctions(): void
6361
{
6462
require_once __DIR__ . '/data/annotations-final.php';
6563

66-
/** @var Broker $broker */
67-
$broker = self::getContainer()->getByType(Broker::class);
64+
$reflectionProvider = $this->createReflectionProvider();
6865

69-
$this->assertFalse($broker->getFunction(new Name\FullyQualified('FinalAnnotations\foo'), null)->isFinal()->yes());
70-
$this->assertTrue($broker->getFunction(new Name\FullyQualified('FinalAnnotations\finalFoo'), null)->isFinal()->yes());
66+
$this->assertFalse($reflectionProvider->getFunction(new Name\FullyQualified('FinalAnnotations\foo'), null)->isFinal()->yes());
67+
$this->assertTrue($reflectionProvider->getFunction(new Name\FullyQualified('FinalAnnotations\finalFoo'), null)->isFinal()->yes());
7168
}
7269

7370
}

tests/PHPStan/Reflection/Annotations/InternalAnnotationsTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node\Name;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Broker\Broker;
87

98
class InternalAnnotationsTest extends \PHPStan\Testing\PHPStanTestCase
109
{
@@ -111,9 +110,8 @@ public function dataInternalAnnotations(): array
111110
*/
112111
public function testInternalAnnotations(bool $internal, string $className, array $internalAnnotations): void
113112
{
114-
/** @var Broker $broker */
115-
$broker = self::getContainer()->getByType(Broker::class);
116-
$class = $broker->getClass($className);
113+
$reflectionProvider = $this->createReflectionProvider();
114+
$class = $reflectionProvider->getClass($className);
117115
$scope = $this->createMock(Scope::class);
118116
$scope->method('isInClass')->willReturn(true);
119117
$scope->method('getClassReflection')->willReturn($class);
@@ -141,11 +139,10 @@ public function testInternalUserFunctions(): void
141139
{
142140
require_once __DIR__ . '/data/annotations-internal.php';
143141

144-
/** @var Broker $broker */
145-
$broker = self::getContainer()->getByType(Broker::class);
142+
$reflectionProvider = $this->createReflectionProvider();
146143

147-
$this->assertFalse($broker->getFunction(new Name\FullyQualified('InternalAnnotations\foo'), null)->isInternal()->yes());
148-
$this->assertTrue($broker->getFunction(new Name\FullyQualified('InternalAnnotations\internalFoo'), null)->isInternal()->yes());
144+
$this->assertFalse($reflectionProvider->getFunction(new Name\FullyQualified('InternalAnnotations\foo'), null)->isInternal()->yes());
145+
$this->assertTrue($reflectionProvider->getFunction(new Name\FullyQualified('InternalAnnotations\internalFoo'), null)->isInternal()->yes());
149146
}
150147

151148
}

tests/PHPStan/Reflection/Annotations/ThrowsAnnotationsTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node\Name;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Broker\Broker;
87
use PHPStan\Type\VerbosityLevel;
98

109
class ThrowsAnnotationsTest extends \PHPStan\Testing\PHPStanTestCase
@@ -68,9 +67,8 @@ public function dataThrowsAnnotations(): array
6867
*/
6968
public function testThrowsAnnotations(string $className, array $throwsAnnotations): void
7069
{
71-
/** @var Broker $broker */
72-
$broker = self::getContainer()->getByType(Broker::class);
73-
$class = $broker->getClass($className);
70+
$reflectionProvider = $this->createReflectionProvider();
71+
$class = $reflectionProvider->getClass($className);
7472
$scope = $this->createMock(Scope::class);
7573

7674
foreach ($throwsAnnotations as $methodName => $type) {
@@ -84,12 +82,11 @@ public function testThrowsOnUserFunctions(): void
8482
{
8583
require_once __DIR__ . '/data/annotations-throws.php';
8684

87-
/** @var Broker $broker */
88-
$broker = self::getContainer()->getByType(Broker::class);
85+
$reflectionProvider = $this->createReflectionProvider();
8986

90-
$this->assertNull($broker->getFunction(new Name\FullyQualified('ThrowsAnnotations\withoutThrows'), null)->getThrowType());
87+
$this->assertNull($reflectionProvider->getFunction(new Name\FullyQualified('ThrowsAnnotations\withoutThrows'), null)->getThrowType());
9188

92-
$throwType = $broker->getFunction(new Name\FullyQualified('ThrowsAnnotations\throwsRuntime'), null)->getThrowType();
89+
$throwType = $reflectionProvider->getFunction(new Name\FullyQualified('ThrowsAnnotations\throwsRuntime'), null)->getThrowType();
9390
$this->assertNotNull($throwType);
9491
$this->assertSame(\RuntimeException::class, $throwType->describe(VerbosityLevel::typeOnly()));
9592
}

0 commit comments

Comments
 (0)