Skip to content

Commit fc1abf2

Browse files
committed
Simplifying tests thanks to PHPStan's TestCase available as part of src/ directory in dist package
1 parent 6ad0f3d commit fc1abf2

File tree

2 files changed

+10
-46
lines changed

2 files changed

+10
-46
lines changed

tests/PHPStan/Reflection/Doctrine/DoctrineSelectableClassReflectionExtensionTest.php

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
namespace Tests\PHPStan\Reflection\Doctrine;
44

5-
use PHPStan\Broker\Broker;
6-
use PHPStan\Reflection\ClassReflection;
75
use PHPStan\Reflection\Doctrine\DoctrineSelectableClassReflectionExtension;
8-
use PHPStan\Reflection\MethodReflection;
9-
use PHPStan\Reflection\Php\PhpMethodReflection;
10-
use PHPUnit\Framework\TestCase;
116

12-
final class DoctrineSelectableClassReflectionExtensionTest extends TestCase
7+
final class DoctrineSelectableClassReflectionExtensionTest extends \PHPStan\Testing\TestCase
138
{
149

10+
/** @var \PHPStan\Broker\Broker */
11+
private $broker;
12+
1513
/** @var \PHPStan\Reflection\Doctrine\DoctrineSelectableClassReflectionExtension */
1614
private $extension;
1715

1816
protected function setUp()
1917
{
20-
$broker = $this->mockBroker();
18+
$this->broker = $this->createBroker();
2119

2220
$this->extension = new DoctrineSelectableClassReflectionExtension();
23-
$this->extension->setBroker($broker);
21+
$this->extension->setBroker($this->broker);
2422
}
2523

2624
/**
@@ -42,48 +40,15 @@ public function dataHasMethod(): array
4240
*/
4341
public function testHasMethod(string $className, string $method, bool $expectedResult)
4442
{
45-
$classReflection = $this->mockClassReflection(new \ReflectionClass($className));
43+
$classReflection = $this->broker->getClass($className);
4644
$this->assertSame($expectedResult, $this->extension->hasMethod($classReflection, $method));
4745
}
4846

4947
public function testGetMethod()
5048
{
51-
$classReflection = $this->mockClassReflection(new \ReflectionClass(\Doctrine\Common\Collections\Collection::class));
49+
$classReflection = $this->broker->getClass(\Doctrine\Common\Collections\Collection::class);
5250
$methodReflection = $this->extension->getMethod($classReflection, 'matching');
5351
$this->assertSame('matching', $methodReflection->getName());
5452
}
5553

56-
private function mockBroker(): Broker
57-
{
58-
$broker = $this->createMock(Broker::class);
59-
60-
$broker->method('getClass')->willReturnCallback(
61-
function (string $className): ClassReflection {
62-
return $this->mockClassReflection(new \ReflectionClass($className));
63-
}
64-
);
65-
66-
return $broker;
67-
}
68-
69-
private function mockClassReflection(\ReflectionClass $reflectionClass): ClassReflection
70-
{
71-
$classReflection = $this->createMock(ClassReflection::class);
72-
$classReflection->method('getName')->willReturn($reflectionClass->getName());
73-
$classReflection->method('getNativeMethod')->willReturnCallback(
74-
function (string $method) use ($reflectionClass): MethodReflection {
75-
return $this->mockMethodReflection($reflectionClass->getMethod($method));
76-
}
77-
);
78-
79-
return $classReflection;
80-
}
81-
82-
private function mockMethodReflection(\ReflectionMethod $method): PhpMethodReflection
83-
{
84-
$methodReflection = $this->createMock(PhpMethodReflection::class);
85-
$methodReflection->method('getName')->willReturn($method->getName());
86-
return $methodReflection;
87-
}
88-
8954
}

tests/PHPStan/Type/Doctrine/DoctrineSelectableDynamicReturnTypeExtensionTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ public function testGetTypeFromMethodCall()
5353
$scope = $this->createMock(Scope::class);
5454
$scope->method('getType')->will(
5555
self::returnCallback(
56-
function (\PhpParser\Node\Expr $node): Type {
57-
return new ObjectType($node->getType());
56+
function (): Type {
57+
return new ObjectType(\Doctrine\Common\Collections\Collection::class);
5858
}
5959
)
6060
);
6161

6262
$var = $this->createMock(Expr::class);
63-
$var->method('getType')->willReturn(\Doctrine\Common\Collections\Collection::class);
6463
$methodCall = $this->createMock(MethodCall::class);
6564
$methodCall->var = $var;
6665

0 commit comments

Comments
 (0)