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\AnnotatedObject; |
13
|
|
|
use Yiistack\Annotated\Tests\Stub\Annotation\Assert; |
14
|
|
|
|
15
|
|
|
class AnnotationLoaderTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public function testFindProperties() |
19
|
|
|
{ |
20
|
|
|
$properties = $this->getAnnotationLoader() |
21
|
|
|
->withTargets([AnnotatedObject::class]) |
22
|
|
|
->findProperties(Assert::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([AnnotatedObject::class]) |
34
|
|
|
->findClasses(Assert::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([AnnotatedObject::class]) |
46
|
|
|
->findMethods(Assert::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
|
|
|
|