Created
October 1, 2013 07:44
Revisions
-
JJK801 created this gist
Oct 1, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ <?php namespace M6\Bundle\MyBundle\Tests\Units\Listener; use M6\Bundle\MyBundle\Listener; use Symfony\Component\HttpFoundation\Request; class MyEventSubscriber { public function testOnRequest() { $request = $this->getRequestMock(‘/tested/path’); $event = $this->getGetResponseEventMock($request); $helper = $this->getMyHelperMock(array( ‘pathInfo’ => ‘/tested/path’, )); $subscriber = new Listener\MyEventSubscriber($helper); $subscriber->onRequest($event); $this->mock($helper)->call(‘doSomething’)->once(); } protected function getRequestMock($path) { $request = new \mock\Symfony\Component\HttpFoundation\Request(); $request->getMockController()->getPathInfo = function () use ($path) { return $path; }; return $request; } protected function getGetResponseEventMock(Request $request) { $this->mockGenerator->orphanize('__construct'); $event = new \mock\Symfony\Component\HttpKernel\Event\GetResponseEvent(); $event->getMockController()->getRequest = function () use ($request) { return $request; }; return $event; } protected function getMyHelperMock($data = array()) { $this->mockGenerator->orphanize('__construct'); $self = $this; $helper = new \mock\M6\Bundle\MyBundle\Helper\MyHelper(); $helper->getMockController()->doSomething = function ($pathInfo) use ($self, $data) { if (isset($data[‘pathInfo’])) { // If pathInfo key exists, data is tested $self ->assert ->string($pathInfo) ->isIdenticalTo($data[‘pathInfo’]); } }; return $helper; } }