ClassMethodAnnotationReaderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 21
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readDataProvider() 0 12 1
A setUp() 0 4 1
A testRead() 0 16 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\Annotations;
12
13
use PHPUnit\Framework\TestCase;
14
use Doctrine\Common\Annotations\AnnotationReader;
15
use Yarhon\RouteGuardBundle\Annotations\ClassMethodAnnotationReader;
16
use Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController;
17
use Yarhon\RouteGuardBundle\Tests\Fixtures\Annotation\TestOne;
18
use Yarhon\RouteGuardBundle\Tests\Fixtures\Annotation\TestTwo;
19
use Yarhon\RouteGuardBundle\Tests\Fixtures\Annotation\TestThree;
20
21
/**
22
 * @author Yaroslav Honcharuk <[email protected]>
23
 */
24
class ClassMethodAnnotationReaderTest extends TestCase
25
{
26
    private $readerDelegate;
27
28
    private $reader;
29
30
    public function setUp()
31
    {
32
        $this->readerDelegate = $this->createMock(AnnotationReader::class);
33
        $this->reader = new ClassMethodAnnotationReader($this->readerDelegate);
34
    }
35
36
    /**
37
     * @dataProvider readDataProvider
38
     */
39
    public function testRead($classAnnotations, $methodAnnotations, $expected)
40
    {
41
        $classesToRead = [
42
            TestOne::class,
43
            TestTwo::class,
44
        ];
45
46
        $this->readerDelegate->method('getClassAnnotations')
47
            ->willReturn($classAnnotations);
48
49
        $this->readerDelegate->method('getMethodAnnotations')
50
            ->willReturn($methodAnnotations);
51
52
        $annotations = $this->reader->read(SimpleController::class, 'index', $classesToRead);
53
54
        $this->assertEquals($expected, $annotations);
55
    }
56
57
    public function readDataProvider()
58
    {
59
        return [
60
            [
61
                [new TestOne(['value' => 'v1'])],
62
                [new TestThree(['value' => 'v4'])],
63
                [new TestOne(['value' => 'v1'])],
64
            ],
65
            [
66
                [new TestOne(['value' => 'v1'])],
67
                [new TestTwo(['value' => 'v2']), new TestOne(['value' => 'v3'])],
68
                [new TestOne(['value' => 'v1']), new TestTwo(['value' => 'v2']), new TestOne(['value' => 'v3'])],
69
            ],
70
        ];
71
    }
72
}
73