|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yiistack\Annotated\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Spiral\Tokenizer\ClassLocator; |
|
7
|
|
|
use Symfony\Component\Finder\Finder; |
|
8
|
|
|
use Yiistack\Annotated\AnnotatedClass; |
|
9
|
|
|
use Yiistack\Annotated\AnnotatedMethod; |
|
10
|
|
|
use Yiistack\Annotated\AnnotatedProperty; |
|
11
|
|
|
use Yiistack\Annotated\AnnotationLoader; |
|
12
|
|
|
use Yiistack\Annotated\Tests\Stub\TestClass; |
|
13
|
|
|
use Yiistack\Annotated\Tests\Stub\Annotation\Thing; |
|
14
|
|
|
|
|
15
|
|
|
class AnnotationLoaderTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
public function testFindProperties() |
|
19
|
|
|
{ |
|
20
|
|
|
$properties = $this->getAnnotationLoader() |
|
21
|
|
|
->withTargets([TestClass::class]) |
|
22
|
|
|
->findProperties(Thing::class); |
|
23
|
|
|
|
|
24
|
|
|
$properties = iterator_to_array($properties); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertCount(1, $properties); |
|
27
|
|
|
$this->assertContainsOnlyInstancesOf(AnnotatedProperty::class, $properties); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testFindClasses() |
|
31
|
|
|
{ |
|
32
|
|
|
$classes = $this->getAnnotationLoader() |
|
33
|
|
|
->withTargets([TestClass::class]) |
|
34
|
|
|
->findClasses(Thing::class); |
|
35
|
|
|
|
|
36
|
|
|
$classes = iterator_to_array($classes); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertCount(1, $classes); |
|
39
|
|
|
$this->assertContainsOnlyInstancesOf(AnnotatedClass::class, $classes); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testFindMethods() |
|
43
|
|
|
{ |
|
44
|
|
|
$methods = $this->getAnnotationLoader() |
|
45
|
|
|
->withTargets([TestClass::class]) |
|
46
|
|
|
->findMethods(Thing::class); |
|
47
|
|
|
|
|
48
|
|
|
$methods = iterator_to_array($methods); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertCount(1, $methods); |
|
51
|
|
|
$this->assertContainsOnlyInstancesOf(AnnotatedMethod::class, $methods); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getAnnotationLoader() |
|
55
|
|
|
{ |
|
56
|
|
|
$locator = new ClassLocator(Finder::create()->in(__DIR__ . '/Stub')->name('*.php')); |
|
57
|
|
|
|
|
58
|
|
|
return new AnnotationLoader($locator); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|