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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
} |
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.