Passed
Push — master ( 2353b1...3cbe26 )
by Rustam
01:15
created

AnnotationLoaderTest::getAnnotationLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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