RouteDataCollectorTest::createTestBag()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Cache\DataCollector;
12
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Component\Routing\Route;
15
use Yarhon\RouteGuardBundle\Controller\ControllerMetadata;
16
use Yarhon\RouteGuardBundle\Controller\ControllerMetadataFactory;
17
use Yarhon\RouteGuardBundle\Routing\RouteMetadata;
18
use Yarhon\RouteGuardBundle\Routing\RouteMetadataFactory;
19
use Yarhon\RouteGuardBundle\Security\TestProvider\ProviderAggregate;
20
use Yarhon\RouteGuardBundle\Security\Test\TestBagInterface;
21
use Yarhon\RouteGuardBundle\Cache\DataCollector\RouteDataCollector;
22
23
/**
24
 * @author Yaroslav Honcharuk <[email protected]>
25
 */
26
class RouteDataCollectorTest extends TestCase
27
{
28
    private $testProvider;
29
30
    private $controllerMetadataFactory;
31
32
    private $routeMetadataFactory;
33
34
    private $collector;
35
36
    public function setUp()
37
    {
38
        $this->testProvider = $this->createMock(ProviderAggregate::class);
39
        $this->controllerMetadataFactory = $this->createMock(ControllerMetadataFactory::class);
40
        $this->routeMetadataFactory = $this->createMock(RouteMetadataFactory::class);
41
42
        $this->collector = new RouteDataCollector($this->testProvider, $this->controllerMetadataFactory, $this->routeMetadataFactory);
43
    }
44
45
    public function testCollect()
46
    {
47
        $controllerMetadata = new ControllerMetadata('class::method', 'class', 'method');
48
        $routeMetadata = new RouteMetadata([], []);
49
        $testBags = [$this->createTestBag()];
50
51
        $this->controllerMetadataFactory->method('createMetadata')
52
            ->willReturn($controllerMetadata);
53
54
        $this->routeMetadataFactory->method('createMetadata')
55
            ->willReturn($routeMetadata);
56
57
        $this->testProvider->method('getTests')
58
            ->willReturn($testBags);
59
60
        $collected = $this->collector->collect('index', new Route('/'), 'class::method');
61
62
        $expected = [$testBags, $controllerMetadata, $routeMetadata];
63
64
        $this->assertSame($expected, $collected);
65
    }
66
67
    public function testCollectNoControllerName()
68
    {
69
        $routeMetadata = new RouteMetadata([], []);
70
        $testBags = [$this->createTestBag()];
71
72
        $this->routeMetadataFactory->method('createMetadata')
73
            ->willReturn($routeMetadata);
74
75
        $this->testProvider->method('getTests')
76
            ->willReturn($testBags);
77
78
        $collected = $this->collector->collect('index', new Route('/'), null);
79
80
        $expected = [$testBags, null, $routeMetadata];
81
82
        $this->assertSame($expected, $collected);
83
    }
84
85
    private function createTestBag()
86
    {
87
        return $this->createMock(TestBagInterface::class);
88
    }
89
}
90