Skip to content

Commit a85d4bf

Browse files
author
Adam Grabek
committed
new event manager tests for module.php
1 parent a789bba commit a85d4bf

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

ModuleTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Creator: adamgrabek
4+
* Date: 08.06.2016
5+
* Time: 00:06
6+
*/
7+
8+
namespace ZF\ApiProblem;
9+
10+
use PHPUnit_Framework_TestCase as TestCase;
11+
use Zend\EventManager\EventManager;
12+
use Zend\EventManager\SharedEventManager;
13+
use Zend\Mvc\Application;
14+
use Zend\Mvc\MvcEvent;
15+
use Zend\Mvc\SendResponseListener;
16+
use Zend\ServiceManager\ServiceLocatorInterface;
17+
use ZF\ApiProblem\Listener\ApiProblemListener;
18+
use ZF\ApiProblem\Listener\SendApiProblemResponseListener;
19+
20+
21+
class ModuleTest extends TestCase
22+
{
23+
24+
public function testOnBootstrap()
25+
{
26+
$module = new Module();
27+
28+
29+
$application = $this->getMock(Application::class, [], [], '', FALSE);
30+
$serviceLocator = $this->getMockForAbstractClass(ServiceLocatorInterface::class);
31+
$serviceLocator->method('get')->will($this->returnCallback([$this, 'serviceLocator']));
32+
33+
$eventManager = new EventManager(new SharedEventManager());
34+
$event = $this->getMock(MvcEvent::class);
35+
36+
37+
$application->method('getServiceManager')->willReturn($serviceLocator);
38+
$application->method('getEventManager')->willReturn($eventManager);
39+
$event->expects($this->once())->method('getTarget')->willReturn($application);
40+
41+
$module->onBootstrap($event);
42+
}
43+
44+
45+
public function serviceLocator($service)
46+
{
47+
switch ($service) {
48+
case 'ZF\ApiProblem\Listener\ApiProblemListener':
49+
return new ApiProblemListener();
50+
break;
51+
case 'SendResponseListener':
52+
$listener = $this->getMock(SendResponseListener::class);
53+
$listener->method('getEventManager')->willReturn(new EventManager());
54+
55+
return $listener;
56+
break;
57+
case SendApiProblemResponseListener::class :
58+
return new SendApiProblemResponseListener();
59+
default:
60+
//
61+
}
62+
}
63+
}

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
<testsuite name="ZFApiProblem Module Tests">
44
<directory>./test</directory>
55
</testsuite>
6+
<testsuite name="ZFApiProblem Module Class tests">
7+
<file>./ModuleTest.php</file>
8+
</testsuite>
69
</testsuites>
710
</phpunit>

0 commit comments

Comments
 (0)