|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Go\ZF2\GoAopModule\Tests\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Go\Aop\Aspect; |
|
6
|
|
|
use Go\Core\AspectContainer; |
|
7
|
|
|
use Go\ZF2\GoAopModule\Module; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Prophecy\Argument; |
|
10
|
|
|
use Zend\EventManager\EventManagerInterface; |
|
11
|
|
|
use Zend\ModuleManager\ModuleEvent; |
|
12
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
|
13
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @package Go\ZF2\GoAopModule\Tests\Unit |
|
17
|
|
|
*/ |
|
18
|
|
|
class ModuleTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @test |
|
22
|
|
|
*/ |
|
23
|
|
|
public function itReturnsConfig() |
|
24
|
|
|
{ |
|
25
|
|
|
$module = new Module(); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertInternalType( |
|
28
|
|
|
'array', |
|
29
|
|
|
$module->getConfig(), |
|
30
|
|
|
'returned config should be of type array' |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @test |
|
36
|
|
|
*/ |
|
37
|
|
|
public function itAttachesListenerOnInit() |
|
38
|
|
|
{ |
|
39
|
|
|
$module = new Module(); |
|
40
|
|
|
|
|
41
|
|
|
$eventManager = $this->prophesize(EventManagerInterface::class); |
|
42
|
|
|
$eventManager->attach( |
|
43
|
|
|
Argument::exact(ModuleEvent::EVENT_LOAD_MODULES_POST), |
|
44
|
|
|
Argument::exact([$module, 'initializeAspects']) |
|
45
|
|
|
)->shouldBeCalled(); |
|
46
|
|
|
|
|
47
|
|
|
$moduleManager = $this->prophesize(ModuleManagerInterface::class); |
|
48
|
|
|
$moduleManager->getEventManager()->willReturn($eventManager->reveal()); |
|
49
|
|
|
|
|
50
|
|
|
$module->init($moduleManager->reveal()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @test |
|
55
|
|
|
*/ |
|
56
|
|
|
public function itRegisterAspectsOnInitializeAspects() |
|
57
|
|
|
{ |
|
58
|
|
|
$aspect = $this->prophesize(Aspect::class)->reveal(); |
|
59
|
|
|
|
|
60
|
|
|
$aspectContainer = $this->prophesize(AspectContainer::class); |
|
61
|
|
|
$aspectContainer->registerAspect(Argument::exact($aspect)) |
|
62
|
|
|
->shouldBeCalled(); |
|
63
|
|
|
|
|
64
|
|
|
$serviceManager = $this->prophesize(ServiceManager::class); |
|
65
|
|
|
$serviceManager->get(AspectContainer::class) |
|
66
|
|
|
->willReturn($aspectContainer->reveal()) |
|
67
|
|
|
->shouldBeCalled(); |
|
68
|
|
|
$serviceManager->get('config') |
|
69
|
|
|
->willReturn(['goaop_aspect' => ['testAspect']]) |
|
70
|
|
|
->shouldBeCalled(); |
|
71
|
|
|
$serviceManager->get('testAspect') |
|
72
|
|
|
->willReturn($aspect) |
|
73
|
|
|
->shouldBeCalled(); |
|
74
|
|
|
|
|
75
|
|
|
$moduleEvent = $this->prophesize(ModuleEvent::class); |
|
76
|
|
|
$moduleEvent->getParam('ServiceManager') |
|
77
|
|
|
->willReturn($serviceManager->reveal()); |
|
78
|
|
|
|
|
79
|
|
|
$module = new Module(); |
|
80
|
|
|
|
|
81
|
|
|
$module->initializeAspects($moduleEvent->reveal()); |
|
82
|
|
|
} |
|
83
|
|
|
} |