Completed
Push — mssql-community-support ( 893535 )
by Sam
06:55
created

ModuleManifestTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 20.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 19
loc 94
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testGetModules() 0 12 1
A testGetLegacyModule() 0 9 1
A testGetComposerModule() 0 21 1
A testGetResourcePath() 10 10 1
A testGetResourcePathOnRoot() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
namespace SilverStripe\Core\Tests\Manifest;
5
6
use SilverStripe\Core\Manifest\ModuleManifest;
7
use SilverStripe\Dev\SapphireTest;
8
9
class ModuleManifestTest extends SapphireTest
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $base;
15
16
    /**
17
     * @var ModuleManifest
18
     */
19
    protected $manifest;
20
21
    protected function setUp()
22
    {
23
        parent::setUp();
24
25
        $this->base = dirname(__FILE__) . '/fixtures/classmanifest';
26
        $this->manifest = new ModuleManifest($this->base, false);
27
    }
28
29
    public function testGetModules()
30
    {
31
        $modules = $this->manifest->getModules();
32
        $this->assertEquals(
33
            [
34
                'silverstripe/root-module',
35
                'module',
36
                'silverstripe/awesome-module',
37
            ],
38
            array_keys($modules)
39
        );
40
    }
41
42
    public function testGetLegacyModule()
43
    {
44
        $module = $this->manifest->getModule('module');
45
        $this->assertNotEmpty($module);
46
        $this->assertEquals('module', $module->getName());
47
        $this->assertEquals('module', $module->getShortName());
48
        $this->assertEquals('module', $module->getRelativePath());
49
        $this->assertEmpty($module->getComposerName());
50
    }
51
52
    public function testGetComposerModule()
53
    {
54
        // Get by installer-name (folder)
55
        $moduleByShortName = $this->manifest->getModule('moduleb');
56
        $this->assertNotEmpty($moduleByShortName);
57
58
        // Can also get this by full composer name
59
        $module = $this->manifest->getModule('silverstripe/awesome-module');
60
        $this->assertNotEmpty($module);
61
        $this->assertEquals($moduleByShortName->getPath(), $module->getPath());
62
63
        // correctly respects vendor
64
        $this->assertEmpty($this->manifest->getModule('wrongvendor/awesome-module'));
65
        $this->assertEmpty($this->manifest->getModule('wrongvendor/moduleb'));
66
67
        // Properties of module
68
        $this->assertEquals('silverstripe/awesome-module', $module->getName());
69
        $this->assertEquals('silverstripe/awesome-module', $module->getComposerName());
70
        $this->assertEquals('moduleb', $module->getShortName());
71
        $this->assertEquals('moduleb', $module->getRelativePath());
72
    }
73
74
    /*
75
     * Note: Tests experimental API
76
     * @internal
77
     */
78 View Code Duplication
    public function testGetResourcePath()
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...
79
    {
80
        $module = $this->manifest->getModule('moduleb');
81
        $this->assertTrue($module->hasResource('composer.json'));
82
        $this->assertFalse($module->hasResource('package.json'));
83
        $this->assertEquals(
84
            'moduleb/composer.json',
85
            $module->getResourcePath('composer.json')
86
        );
87
    }
88
89
    /*
90
     * Note: Tests experimental API
91
     * @internal
92
     */
93 View Code Duplication
    public function testGetResourcePathOnRoot()
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...
94
    {
95
        $module = $this->manifest->getModule('silverstripe/root-module');
96
        $this->assertTrue($module->hasResource('composer.json'));
97
        $this->assertEquals(
98
            'composer.json',
99
            $module->getResourcePath('composer.json')
100
        );
101
    }
102
}
103