testGetTestsWhenNoConstraintMatches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.9666
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\Http;
12
13
use PHPUnit\Framework\TestCase;
14
use Yarhon\RouteGuardBundle\Security\Http\RequestDependentTestBag;
15
use Yarhon\RouteGuardBundle\Security\Test\TestInterface;
16
use Yarhon\RouteGuardBundle\Security\Http\RequestConstraintInterface;
17
use Yarhon\RouteGuardBundle\Security\Http\RequestContext;
18
19
/**
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
class RequestDependentTestBagTest extends TestCase
23
{
24
    private $testArrays;
25
26
    private $constraints;
27
28
    private $context;
29
30
    public function setUp()
31
    {
32
        $this->testArrays = [
33
            [$this->createMock(TestInterface::class)],
34
            [$this->createMock(TestInterface::class)],
35
        ];
36
37
        $this->constraints = [
38
            $this->createMock(RequestConstraintInterface::class),
39
            $this->createMock(RequestConstraintInterface::class),
40
        ];
41
42
        $this->context = $this->createMock(RequestContext::class);
43
    }
44
45
    public function testGetTestsWhenConstraintMatches()
46
    {
47
        $this->constraints[0]->method('matches')
48
            ->willReturn(false);
49
50
        $this->constraints[1]->method('matches')
51
            ->willReturn(true);
52
53
        $map = [
54
            [$this->testArrays[0], $this->constraints[0]],
55
            [$this->testArrays[1], $this->constraints[1]],
56
        ];
57
58
        $testBag = new RequestDependentTestBag($map);
59
60
        $this->assertSame($this->testArrays[1], $testBag->getTests($this->context));
61
    }
62
63
    public function testGetTestsWhenNoConstraintMatches()
64
    {
65
        $this->constraints[0]->method('matches')
66
            ->willReturn(false);
67
68
        $this->constraints[1]->method('matches')
69
            ->willReturn(false);
70
71
        $map = [
72
            [$this->testArrays[0], $this->constraints[0]],
73
            [$this->testArrays[1], $this->constraints[1]],
74
        ];
75
76
        $testBag = new RequestDependentTestBag($map);
77
78
        $this->assertEquals([], $testBag->getTests($this->context));
79
    }
80
81
    public function testGetTestsWhenConstraintIsNull()
82
    {
83
        $this->constraints[0]->method('matches')
84
            ->willReturn(false);
85
86
        $map = [
87
            [$this->testArrays[0], $this->constraints[0]],
88
            [$this->testArrays[1], null],
89
        ];
90
91
        $testBag = new RequestDependentTestBag($map);
92
93
        $this->assertSame($this->testArrays[1], $testBag->getTests($this->context));
94
    }
95
}
96