Completed
Push — master ( 0e2bb1...d48330 )
by WEBEWEB
02:01
created

AbstractThemeManagerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 95
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddGlobal() 0 16 1
A testAddGlobalWithNull() 0 9 1
A testSetProvider() 0 10 1
A testSetProviderWithOverwrite() 0 14 1
A test__construct() 0 10 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 Exception;
15
use WBW\Bundle\CoreBundle\Provider\ThemeProviderInterface;
16
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
17
use WBW\Bundle\CoreBundle\Tests\Fixtures\Manager\TestThemeManager;
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
     * Tests the addGlobal() method.
29
     *
30
     * @return void
31
     * @throws Exception 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);
0 ignored issues
show
Documentation introduced by
$res is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
46
        $this->assertArrayHasKey("ThemeProvider", $res);
47
        $this->assertInstanceOf(ThemeProviderInterface::class, $res["ThemeProvider"]);
48
    }
49
50
    /**
51
     * Tests the addGlobal() method.
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);
0 ignored issues
show
Documentation introduced by
$res is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
    }
64
65
    /**
66
     * Tests the setProvider() method.
67
     *
68
     * @return void
69
     * @throws Exception 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
     * Tests the setProvider() method.
84
     *
85
     * @return void
86
     * @throws Exception 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
     * Tests the __construct() method.
105
     *
106
     * @return void
107
     * @throws Exception 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());
0 ignored issues
show
Documentation introduced by
$obj->getProviders() is of type array<integer,object<WBW...der\ProviderInterface>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
117
        $this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment());
118
    }
119
}
120