TestLoaderTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
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;
12
13
use PHPUnit\Framework\TestCase;
14
use Psr\Cache\CacheItemPoolInterface;
15
use Symfony\Component\Cache\Adapter\ArrayAdapter;
16
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface;
17
use Yarhon\RouteGuardBundle\Security\Test\TestInterface;
18
use Yarhon\RouteGuardBundle\Security\TestBagResolver\TestBagResolverInterface;
19
use Yarhon\RouteGuardBundle\Routing\RouteContext;
20
use Yarhon\RouteGuardBundle\Security\TestLoader;
21
22
/**
23
 * @author Yaroslav Honcharuk <[email protected]>
24
 */
25
class TestLoaderTest extends TestCase
26
{
27
    private $testsCache;
28
29
    private $testBagResolver;
30
31
    private $loader;
32
33
    public function setUp()
34
    {
35
        $this->testsCache = new ArrayAdapter(0, false);
36
37
        $this->testBagResolver = $this->createMock(TestBagResolverInterface::class);
38
39
        $this->loader = new TestLoader($this->testsCache, $this->testBagResolver);
40
    }
41
42
    private function addTestsCacheItem($name, $value)
43
    {
44
        $cacheItem = $this->testsCache->getItem($name);
45
        $cacheItem->set($value);
46
        $this->testsCache->save($cacheItem);
47
    }
48
49
    public function testLoad()
50
    {
51
        $testOne = $this->createMock(TestInterface::class);
52
        $testTwo = $this->createMock(TestInterface::class);
53
54
        $this->testBagResolver->method('resolve')
55
            ->willReturnOnConsecutiveCalls([$testOne], [$testTwo]);
56
57
        $testBagOne = $this->createMock(AbstractTestBagInterface::class);
58
        $testBagTwo = $this->createMock(AbstractTestBagInterface::class);
59
60
        $this->addTestsCacheItem('index', [$testBagOne, $testBagTwo]);
61
62
        $routeContext = new RouteContext('index');
63
64
        $tests = $this->loader->load($routeContext);
65
66
        $this->assertSame([$testOne, $testTwo], $tests);
67
    }
68
69
    public function testLoadNoCacheItem()
70
    {
71
        $routeContext = new RouteContext('index');
72
        $tests = $this->loader->load($routeContext);
73
        $this->assertSame([], $tests);
74
    }
75
}
76