-
Notifications
You must be signed in to change notification settings - Fork 479
/
Copy pathAutoloadSourceLocatorTest.php
56 lines (44 loc) · 2.48 KB
/
AutoloadSourceLocatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php declare(strict_types = 1);
namespace PHPStan\Reflection\BetterReflection\SourceLocator;
use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PHPStan\BetterReflection\Reflector\DefaultReflector;
use PHPStan\Testing\PHPStanTestCase;
use TestSingleFileSourceLocator\AFoo;
use TestSingleFileSourceLocator\InCondition;
function testFunctionForLocator(): void // phpcs:disable
{
}
class AutoloadSourceLocatorTest extends PHPStanTestCase
{
public function testAutoloadEverythingInFile(): void
{
$locator = new AutoloadSourceLocator(self::getContainer()->getByType(FileNodesFetcher::class), false);
$reflector = new DefaultReflector($locator);
$aFoo = $reflector->reflectClass(AFoo::class);
$this->assertNotNull($aFoo->getFileName());
$this->assertSame('a.php', basename($aFoo->getFileName()));
$testFunctionReflection = $reflector->reflectFunction('PHPStan\\Reflection\\BetterReflection\\SourceLocator\testFunctionForLocator');
$this->assertSame(str_replace('\\', '/', __FILE__), $testFunctionReflection->getFileName());
$someConstant = $reflector->reflectConstant('TestSingleFileSourceLocator\\SOME_CONSTANT');
$this->assertNotNull($someConstant->getFileName());
$this->assertSame('a.php', basename($someConstant->getFileName()));
$this->assertSame(1, $someConstant->getValue());
$anotherConstant = $reflector->reflectConstant('TestSingleFileSourceLocator\\ANOTHER_CONSTANT');
$this->assertNotNull($anotherConstant->getFileName());
$this->assertSame('a.php', basename($anotherConstant->getFileName()));
$this->assertSame(2, $anotherConstant->getValue());
$doFooFunctionReflection = $reflector->reflectFunction('TestSingleFileSourceLocator\\doFoo');
$this->assertSame('TestSingleFileSourceLocator\\doFoo', $doFooFunctionReflection->getName());
$this->assertNotNull($doFooFunctionReflection->getFileName());
$this->assertSame('a.php', basename($doFooFunctionReflection->getFileName()));
class_exists(InCondition::class);
$classInCondition = $reflector->reflectClass(InCondition::class);
$classInConditionFilename = $classInCondition->getFileName();
$this->assertNotNull($classInConditionFilename);
$this->assertSame('a.php', basename($classInConditionFilename));
$this->assertSame(InCondition::class, $classInCondition->getName());
$this->assertSame(25, $classInCondition->getStartLine());
$this->assertInstanceOf(ReflectionClass::class, $classInCondition->getParentClass());
$this->assertSame(AFoo::class, $classInCondition->getParentClass()->getName());
}
}