Completed
Push — master ( 236a45...b262d2 )
by Yaroslav
09:39
created

ProviderAggregateTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 42
dl 0
loc 75
rs 10
c 0
b 0
f 0

4 Methods

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