Completed
Push — master ( c7c355...0c2e1a )
by Alejandro
08:38
created

TestLoaderModule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 16
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onConfigChange() 0 3 1
A onLoad() 0 3 1
A onRemove() 0 3 1
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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