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