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

LoaderCollectionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 81.93 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoadersVisibility() 0 6 1
A testAddLoaderKey() 15 15 1
A testAddLoader() 15 15 1
A testHasLoaderPassed() 9 9 1
A testHasLoaderFailed() 9 9 1
A testGetLoaderPassed() 9 9 1
A testGetLoaderFailed() 11 11 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
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
8
9
/**
10
 * Class LoaderCollectionTest
11
 *
12
 * @see Majora\Framework\Loader\LoaderCollection
13
 */
14
class LoaderCollectionTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testLoadersVisibility()
17
    {
18
        $reflection = new \ReflectionProperty(LoaderCollection::class, 'loaders');
19
20
        $this->assertTrue($reflection->isPrivate());
21
    }
22
23 View Code Duplication
    public function testAddLoaderKey()
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...
24
    {
25
        $loader = $this->prophesize(LoaderInterface::class)->reveal();
26
27
        $collection = new LoaderCollection();
28
        $collection->add('test', $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('test', key($loaders));
37
    }
38
39 View Code Duplication
    public function testAddLoader()
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->prophesize(LoaderInterface::class)->reveal();
42
43
        $collection = new LoaderCollection();
44
        $collection->add('test', $loader);
45
46
        $reflection = new \ReflectionProperty(LoaderCollection::class, 'loaders');
47
        $reflection->setAccessible(true);
48
        $loaders = $reflection->getValue($collection);
49
50
        reset($loaders);
51
52
        $this->assertEquals($loader, current($loaders));
53
    }
54
55 View Code Duplication
    public function testHasLoaderPassed()
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...
56
    {
57
        $loader = $this->prophesize(LoaderInterface::class)->reveal();
58
59
        $collection = new LoaderCollection();
60
        $collection->add('test', $loader);
61
62
        $this->assertTrue($collection->has('test'));
63
    }
64
65 View Code Duplication
    public function testHasLoaderFailed()
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...
66
    {
67
        $loader = $this->prophesize(LoaderInterface::class)->reveal();
68
69
        $collection = new LoaderCollection();
70
        $collection->add('test', $loader);
71
72
        $this->assertFalse($collection->has('toto'));
73
    }
74
75 View Code Duplication
    public function testGetLoaderPassed()
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...
76
    {
77
        $loader = $this->prophesize(LoaderInterface::class)->reveal();
78
79
        $collection = new LoaderCollection();
80
        $collection->add('test', $loader);
81
82
        $this->assertEquals($loader, $collection->get('test'));
83
    }
84
85 View Code Duplication
    public function testGetLoaderFailed()
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
    {
87
        $loader = $this->prophesize(LoaderInterface::class)->reveal();
88
89
        $collection = new LoaderCollection();
90
        $collection->add('test', $loader);
91
        
92
        $this->expectException(\RuntimeException::class);
93
94
        $collection->get('toto');
95
    }
96
}