AbstractThemeManagerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 29
dl 0
loc 93
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test__construct() 0 9 1
A testSetProviderWithOverwrite() 0 13 1
A testSetProvider() 0 9 1
A testAddGlobalWithNull() 0 8 1
A testAddGlobal() 0 15 1
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Tests\Manager;
13
14
use Throwable;
15
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
16
use WBW\Bundle\CoreBundle\Tests\Fixtures\Manager\TestThemeManager;
17
use WBW\Library\Symfony\Provider\ThemeProviderInterface;
18
19
/**
20
 * Abstract theme manager test.
21
 *
22
 * @author webeweb <https://github.com/webeweb>
23
 * @package WBW\Bundle\CoreBundle\Tests\Manager
24
 */
25
class AbstractThemeManagerTest extends AbstractTestCase {
26
27
    /**
28
     * Test addGlobal()
29
     *
30
     * @return void
31
     * @throws Throwable Throws an exception if an error occurs.
32
     */
33
    public function testAddGlobal(): void {
34
35
        // Set a Theme provider mock.
36
        $provider = $this->getMockBuilder(ThemeProviderInterface::class)->getMock();
37
38
        $obj = new TestThemeManager($this->logger, $this->twigEnvironment);
39
        $obj->setProvider(ThemeProviderInterface::class, $provider);
40
41
        $obj->addGlobal();
42
43
        $res = $this->twigEnvironment->getGlobals();
44
        $this->assertCount(1, $res);
45
46
        $this->assertArrayHasKey("ThemeProvider", $res);
47
        $this->assertInstanceOf(ThemeProviderInterface::class, $res["ThemeProvider"]);
48
    }
49
50
    /**
51
     * Test addGlobal()
52
     *
53
     * @return void
54
     */
55
    public function testAddGlobalWithNull(): void {
56
57
        $obj = new TestThemeManager($this->logger, $this->twigEnvironment);
58
59
        $obj->addGlobal();
60
61
        $res = $this->twigEnvironment->getGlobals();
62
        $this->assertCount(0, $res);
63
    }
64
65
    /**
66
     * Test setProvider()
67
     *
68
     * @return void
69
     * @throws Throwable Throws an exception if an error occurs.
70
     */
71
    public function testSetProvider(): void {
72
73
        // Set a Theme provider mock.
74
        $provider = $this->getMockBuilder(ThemeProviderInterface::class)->getMock();
75
76
        $obj = new TestThemeManager($this->logger, $this->twigEnvironment);
77
78
        $obj->setProvider(ThemeProviderInterface::class, $provider);
79
        $this->assertSame($provider, $obj->getProvider(ThemeProviderInterface::class));
80
    }
81
82
    /**
83
     * Test setProvider()
84
     *
85
     * @return void
86
     * @throws Throwable Throws an exception if an error occurs.
87
     */
88
    public function testSetProviderWithOverwrite(): void {
89
90
        // Set a Theme provider mock.
91
        $provider1 = $this->getMockBuilder(ThemeProviderInterface::class)->getMock();
92
        $provider2 = $this->getMockBuilder(ThemeProviderInterface::class)->getMock();
93
94
        $obj = new TestThemeManager($this->logger, $this->twigEnvironment);
95
96
        $obj->setProvider(ThemeProviderInterface::class, $provider1);
97
        $this->assertSame($provider1, $obj->getProvider(ThemeProviderInterface::class));
98
99
        $obj->setProvider(ThemeProviderInterface::class, $provider2);
100
        $this->assertSame($provider2, $obj->getProvider(ThemeProviderInterface::class));
101
    }
102
103
    /**
104
     * Test __construct()
105
     *
106
     * @return void
107
     * @throws Throwable Throws an exception if an error occurs.
108
     */
109
    public function test__construct(): void {
110
111
        $obj = new TestThemeManager($this->logger, $this->twigEnvironment);
112
113
        $this->assertSame($this->logger, $obj->getLogger());
114
        $this->assertNull($obj->getProvider(ThemeProviderInterface::class));
115
        $this->assertCount(0, $obj->getProviders());
116
117
        $this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment());
118
    }
119
}
120