Completed
Push — master ( 562140...e835bc )
by Yaroslav
08:17
created

testGetTestsSetsProviderClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 28
rs 9.6666
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\Security\TestProvider;
12
13
use PHPUnit\Framework\TestCase;
14
use Psr\Log\LoggerInterface;
15
use Psr\Log\LoggerAwareInterface;
16
use Symfony\Component\Routing\Route;
17
use Yarhon\RouteGuardBundle\Security\TestProvider\ProviderAggregate;
18
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface;
19
use Yarhon\RouteGuardBundle\Security\Test\ProviderAwareInterface;
20
use Yarhon\RouteGuardBundle\Security\TestProvider\ProviderInterface;
21
use Yarhon\RouteGuardBundle\Controller\ControllerMetadata;
22
use Yarhon\RouteGuardBundle\Exception\LogicException;
23
24
/**
25
 * @author Yaroslav Honcharuk <[email protected]>
26
 */
27
class ProviderAggregateTest extends TestCase
28
{
29
    private $providers;
30
31
    private $logger;
32
33
    public function setUp()
34
    {
35
        $this->providers = [
36
            $this->createMock(ProviderInterface::class),
37
            $this->createMock(ProviderInterface::class),
38
        ];
39
40
        $this->logger = $this->createMock(LoggerInterface::class);
41
    }
42
43
    public function testSetLogger()
44
    {
45
        $providers = [
46
            $this->createMock([ProviderInterface::class, LoggerAwareInterface::class]),
47
        ];
48
49
        $providerAggregate = new ProviderAggregate($providers);
50
51
        $providers[0]->expects($this->once())
52
            ->method('setLogger')
53
            ->with($this->logger);
54
55
        $providerAggregate->setLogger($this->logger);
56
    }
57
58
    public function testGetTests()
59
    {
60
        $providerAggregate = new ProviderAggregate($this->providers);
61
62
        $route = new Route('/');
63
        $routeName = 'index';
64
        $controllerMetadata = new ControllerMetadata('class::method', 'class', 'method');
65
66
        $testBags = [
67
            $this->createMock(AbstractTestBagInterface::class),
68
            $this->createMock(AbstractTestBagInterface::class),
69
        ];
70
71
        $this->providers[0]->expects($this->once())
72
            ->method('getTests')
73
            ->with($routeName, $route, $controllerMetadata)
74
            ->willReturn($testBags[0]);
75
76
        $this->providers[1]->expects($this->once())
77
            ->method('getTests')
78
            ->with($routeName, $route, $controllerMetadata)
79
            ->willReturn($testBags[1]);
80
81
        $tests = $providerAggregate->getTests($routeName, $route, $controllerMetadata);
82
83
        $this->assertSame($testBags, $tests);
84
    }
85
86
    public function testGetTestsSetsProviderClass()
87
    {
88
        $providerAggregate = new ProviderAggregate($this->providers);
89
90
        $route = new Route('/');
91
        $routeName = 'index';
92
        $controllerMetadata = new ControllerMetadata('class::method', 'class', 'method');
93
94
        $testBags = [
95
            $this->createMock([AbstractTestBagInterface::class, ProviderAwareInterface::class]),
96
            $this->createMock([AbstractTestBagInterface::class, ProviderAwareInterface::class]),
97
        ];
98
99
        $this->providers[0]->method('getTests')
100
            ->willReturn($testBags[0]);
101
102
        $this->providers[1]->method('getTests')
103
            ->willReturn($testBags[1]);
104
105
        $testBags[0]->expects($this->once())
106
            ->method('setProviderClass')
107
            ->with(get_class($this->providers[0]));
108
109
        $testBags[1]->expects($this->once())
110
            ->method('setProviderClass')
111
            ->with(get_class($this->providers[1]));
112
113
        $providerAggregate->getTests($routeName, $route, $controllerMetadata);
114
    }
115
}
116