ControllerMetadataTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 19
dl 0
loc 59
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetArgument() 0 3 1
A testGetArgumentException() 0 6 1
A testGetName() 0 3 1
A testGetServiceId() 0 3 1
A testGetClass() 0 3 1
A testGetArguments() 0 4 1
A setUp() 0 8 1
A testGetMethod() 0 3 1
A testHasArgument() 0 4 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\ControllerMetadata;
15
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
16
use Yarhon\RouteGuardBundle\Exception\InvalidArgumentException;
17
18
/**
19
 * @author Yaroslav Honcharuk <[email protected]>
20
 */
21
class ControllerMetadataTest extends TestCase
22
{
23
    private $arguments;
24
25
    private $controllerMetadata;
26
27
    public function setUp()
28
    {
29
        $this->arguments = [
30
            new ArgumentMetadata('arg1', 'int', false, false, null),
31
            new ArgumentMetadata('arg2', 'string', false, false, null),
32
        ];
33
34
        $this->controllerMetadata = new ControllerMetadata('class::method', 'class', 'method', $this->arguments, 'service1');
35
    }
36
37
    public function testGetName()
38
    {
39
        $this->assertSame('class::method', $this->controllerMetadata->getName());
40
    }
41
42
    public function testGetClass()
43
    {
44
        $this->assertSame('class', $this->controllerMetadata->getClass());
45
    }
46
47
    public function testGetMethod()
48
    {
49
        $this->assertSame('method', $this->controllerMetadata->getMethod());
50
    }
51
52
    public function testGetArguments()
53
    {
54
        $expected = array_combine(['arg1', 'arg2'], $this->arguments);
55
        $this->assertSame($expected, $this->controllerMetadata->getArguments());
56
    }
57
58
    public function testHasArgument()
59
    {
60
        $this->assertTrue($this->controllerMetadata->hasArgument('arg1'));
61
        $this->assertFalse($this->controllerMetadata->hasArgument('arg3'));
62
    }
63
64
    public function testGetArgument()
65
    {
66
        $this->assertSame($this->arguments[0], $this->controllerMetadata->getArgument('arg1'));
67
    }
68
69
    public function testGetArgumentException()
70
    {
71
        $this->expectException(InvalidArgumentException::class);
72
        $this->expectExceptionMessage('Invalid argument name: "arg3"');
73
74
        $this->controllerMetadata->getArgument('arg3');
75
    }
76
77
    public function testGetServiceId()
78
    {
79
        $this->assertSame('service1', $this->controllerMetadata->getServiceId());
80
    }
81
}
82