1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Alejandro Peña Florentín ([email protected]). |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24
|
|
|
* THE SOFTWARE. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace Tight\Tests; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Description of ModuleLoaderTest |
31
|
|
|
* |
32
|
|
|
* @author Alejandro Peña Florentín ([email protected]) |
33
|
|
|
*/ |
34
|
|
|
class ModuleLoaderTest extends \PHPUnit_Framework_TestCase |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
private $loader; |
38
|
|
|
private $testModule; |
39
|
|
|
|
40
|
|
|
public function setUp() { |
41
|
|
|
|
42
|
|
|
$this->loader = new \Tight\Modules\ModuleLoader(new \Tight\Tight); |
43
|
|
|
$this->testModule = new TestLoaderModule("TestModule"); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function tearDown() { |
47
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function testModuleLoaderGetModules() { |
54
|
|
|
$expected = []; |
55
|
|
|
$this->assertEquals($expected, $this->loader->getModules()); |
56
|
|
|
$this->assertNull($this->loader->getModule("undefinedModule")); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
* @depends testModuleLoaderGetModules |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function testModuleLoaderAdd() { |
|
|
|
|
64
|
|
|
$key = $this->testModule->getModuleName(); |
65
|
|
|
$expected = [$key => $this->testModule]; |
66
|
|
|
$this->loader->add($this->testModule); |
67
|
|
|
$this->assertEquals($expected, $this->loader->getModules()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
* @depends testModuleLoaderAdd |
73
|
|
|
* @expectedException \Tight\Modules\ModuleException |
74
|
|
|
*/ |
75
|
|
|
public function testModuleLoaderAddWithException() { |
76
|
|
|
$this->loader->add($this->testModule); |
77
|
|
|
$this->setExpectedException("\Tight\Modules\ModuleException"); |
78
|
|
|
$this->loader->add($this->testModule); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @test |
83
|
|
|
* @depends testModuleLoaderAdd |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function testModuleLoaderGetModule() { |
|
|
|
|
86
|
|
|
$this->loader->add($this->testModule); |
87
|
|
|
$modName = $this->testModule->getModuleName(); |
88
|
|
|
$expected = $this->testModule; |
89
|
|
|
$this->assertEquals($expected, $this->loader->getModule($modName)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @test |
94
|
|
|
* @depends testModuleLoaderAdd |
95
|
|
|
*/ |
96
|
|
|
public function testModuleLoaderRemove() { |
97
|
|
|
$this->loader->add($this->testModule); |
98
|
|
|
$this->assertTrue($this->loader->remove($this->testModule->getModuleName())); |
99
|
|
|
$this->assertFalse($this->loader->remove($this->testModule->getModuleName())); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
class TestLoaderModule extends \Tight\Modules\AbstractModule |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
|
107
|
|
|
public function onConfigChange() { |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function onLoad() { |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function onRemove() { |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.