Completed
Pull Request — master (#28)
by Jamal
03:28
created

LoaderCollectionTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 80 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 52
loc 65
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoadersVisibility() 0 6 1
A testAddKey() 16 16 1
A testAddValue() 16 16 1
A testHas() 10 10 1
A testGet() 10 10 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
namespace Majora\Framework\Loader\Tests;
4
5
use Majora\Framework\Loader\LoaderCollection;
6
use Majora\Framework\Loader\LoaderInterface;
7
8
/**
9
 * Class LoaderCollectionTest
10
 *
11
 * @see Majora\Framework\Loader\LoaderCollection
12
 */
13
class LoaderCollectionTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testLoadersVisibility()
16
    {
17
        $reflection = new \ReflectionProperty(LoaderCollection::class, 'loaders');
18
19
        $this->assertTrue($reflection->isPrivate());
20
    }
21
22 View Code Duplication
    public function testAddKey()
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...
23
    {
24
        $loader = $this->createMock(LoaderInterface::class);
25
        $alias = 'test';
26
27
        $collection = new LoaderCollection();
28
        $collection->add($alias, $loader);
29
30
        $reflection = new \ReflectionProperty(LoaderCollection::class, 'loaders');
31
        $reflection->setAccessible(true);
32
        $loaders = $reflection->getValue($collection);
33
34
        reset($loaders);
35
36
        $this->assertEquals($alias, key($loaders));
37
    }
38
39 View Code Duplication
    public function testAddValue()
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...
40
    {
41
        $loader = $this->createMock(LoaderInterface::class);
42
        $alias = 'test';
43
44
        $collection = new LoaderCollection();
45
        $collection->add($alias, $loader);
46
47
        $reflection = new \ReflectionProperty(LoaderCollection::class, 'loaders');
48
        $reflection->setAccessible(true);
49
        $loaders = $reflection->getValue($collection);
50
51
        reset($loaders);
52
53
        $this->assertEquals($loader, current($loaders));
54
    }
55
56 View Code Duplication
    public function testHas()
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...
57
    {
58
        $loader = $this->createMock(LoaderInterface::class);
59
        $alias = 'test';
60
61
        $collection = new LoaderCollection();
62
        $collection->add($alias, $loader);
63
64
        $this->assertTrue($collection->has($alias));
65
    }
66
67 View Code Duplication
    public function testGet()
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...
68
    {
69
        $loader = $this->createMock(LoaderInterface::class);
70
        $alias = 'test';
71
72
        $collection = new LoaderCollection();
73
        $collection->add($alias, $loader);
74
75
        $this->assertEquals($loader, $collection->get($alias));
76
    }
77
}