1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Go\Zend\Framework\Tests\Unit\Factory; |
4
|
|
|
|
5
|
|
|
use Go\Core\AspectContainer; |
6
|
|
|
use Go\Core\AspectKernel; |
7
|
|
|
use Go\Zend\Framework\Factory\AspectContainerFactory; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package Go\Zend\Framework\Tests\Unit\Factory |
13
|
|
|
*/ |
14
|
|
|
class AspectContainerFactoryTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @test |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
public function itCreatesAspectContainerOnInvoke() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$aspectContainer = $this->prophesize(AspectContainer::class); |
22
|
|
|
|
23
|
|
|
$aspectKernel = $this->prophesize(AspectKernel::class); |
24
|
|
|
$aspectKernel->getContainer() |
25
|
|
|
->willReturn($aspectContainer->reveal()) |
26
|
|
|
->shouldBeCalled(); |
27
|
|
|
|
28
|
|
|
$serviceLocator = $this->prophesize(ServiceLocatorInterface::class); |
29
|
|
|
$serviceLocator->get(AspectKernel::class) |
30
|
|
|
->willReturn($aspectKernel->reveal()) |
31
|
|
|
->shouldBeCalled(); |
32
|
|
|
|
33
|
|
|
$factory = new AspectContainerFactory(); |
34
|
|
|
|
35
|
|
|
$instance = $factory($serviceLocator->reveal(), AspectContainer::class); |
36
|
|
|
|
37
|
|
|
$this->assertInstanceOf( |
38
|
|
|
AspectContainer::class, |
39
|
|
|
$instance, |
40
|
|
|
'factory should return an instance of ' . AspectContainer::class |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function itCreatesAspectContainerOnCreateService() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$aspectContainer = $this->prophesize(AspectContainer::class); |
50
|
|
|
|
51
|
|
|
$aspectKernel = $this->prophesize(AspectKernel::class); |
52
|
|
|
$aspectKernel->getContainer() |
53
|
|
|
->willReturn($aspectContainer->reveal()) |
54
|
|
|
->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$serviceLocator = $this->prophesize(ServiceLocatorInterface::class); |
57
|
|
|
$serviceLocator->get(AspectKernel::class) |
58
|
|
|
->willReturn($aspectKernel->reveal()) |
59
|
|
|
->shouldBeCalled(); |
60
|
|
|
|
61
|
|
|
$factory = new AspectContainerFactory(); |
62
|
|
|
|
63
|
|
|
$instance = $factory->createService($serviceLocator->reveal()); |
64
|
|
|
|
65
|
|
|
$this->assertInstanceOf( |
66
|
|
|
AspectContainer::class, |
67
|
|
|
$instance, |
68
|
|
|
'factory should return an instance of ' . AspectContainer::class |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
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.