ControllerNameResolverTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 27
dl 0
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testConverterCall() 0 11 1
A resolveProvider() 0 26 1
A testResolve() 0 5 1
A testResolveException() 0 6 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\Controller;
12
13
use PHPUnit\Framework\TestCase;
14
use Yarhon\RouteGuardBundle\Controller\ControllerNameResolver;
15
use Yarhon\RouteGuardBundle\Controller\ControllerNameConverter;
16
use Yarhon\RouteGuardBundle\Exception\InvalidArgumentException;
17
use Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController;
18
19
/**
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
class ControllerNameResolverTest extends TestCase
23
{
24
    private $resolver;
25
26
    public function setUp()
27
    {
28
        $this->resolver = new ControllerNameResolver();
29
    }
30
31
    /**
32
     * @dataProvider resolveProvider
33
     */
34
    public function testResolve($controller, $expected)
35
    {
36
        $resolved = $this->resolver->resolve($controller);
37
38
        $this->assertSame($expected, $resolved);
39
    }
40
41
    public function resolveProvider()
42
    {
43
        return [
44
            [
45
                [SimpleController::class, 'index'],
46
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController::index',
47
            ],
48
            [
49
                [new SimpleController(), 'index'],
50
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController::index',
51
            ],
52
            [
53
                new SimpleController(),
54
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController::__invoke',
55
            ],
56
            [
57
                'array_map',
58
                null,
59
            ],
60
            [
61
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController',
62
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController::__invoke',
63
            ],
64
            [
65
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController::index',
66
                'Yarhon\RouteGuardBundle\Tests\Fixtures\Controller\SimpleController::index',
67
            ],
68
        ];
69
    }
70
71
    public function testResolveException()
72
    {
73
        $this->expectException(InvalidArgumentException::class);
74
        $this->expectExceptionMessage('Unable to resolve controller name, the controller is not callable.');
75
76
        $this->resolver->resolve([]);
77
    }
78
79
    public function testConverterCall()
80
    {
81
        $converter = $this->createMock(ControllerNameConverter::class);
82
83
        $this->resolver->setConverter($converter);
84
85
        $converter->expects($this->once())
86
            ->method('convert')
87
            ->with('a::b');
88
89
        $this->resolver->resolve('a::b');
90
    }
91
}
92