public function testSetGetService() { $mock = $this->getMock('ServiceFoo'); $serviceName = 'Foo'; $module = 'Bar'; Light_Service_Abstract::setService($mock, $serviceName, $module); $this->assertEquals($mock, Light_Service_Abstract::getService($serviceName, $module)); }
/** * Injects a mock page service into Light_Service_Abstract * * @param PHPUnit_Framework_MockObject_Stub_Return $will * The resoult of the find call */ private function _initPageService($will) { $content = $this->getRequestParam('content'); $language = $this->getRequestParam('language'); $service = $this->getMock('Default_Page_Service', array('find')); $service->expects($this->once())->method('find')->with($content, $language)->will($will); Light_Service_Abstract::setService($service, 'Page', 'Default'); }
public function testShowCallsServiceFind() { $content = 'foo'; $language = 'bar'; $service = $this->getMock('Default_Page_Service', array('find')); $service->expects($this->once())->method('find')->with($content, $language); Light_Service_Abstract::setService($service, 'Page', 'Default'); $this->request->setQuery(array('content' => $content, 'language' => $language)); $this->dispatch('/page/show'); $this->assertModule('default'); $this->assertController('page'); $this->assertAction('show'); }
/** * Displays static pages * * Interacts with the Page service via it's find method, * gets the requested page by content and language, * sets up the returned page to view->page * * @throws Light_Exception_NotFound If the requested page doesn't exist * @throws Light_Exception on internal error */ public function showAction() { $request = $this->getRequest(); $content = $request->getParam('content'); $language = $request->getParam('language'); $service = Light_Service_Abstract::getService('Page', 'Default'); try { $page = $service->find($content, $language); } catch (Light_Exception_NotFound $notFound) { throw new Light_Exception_NotFound('Requested page doesn\'t exists'); } catch (Light_Exception_InvalidParameter $invalid) { throw new Light_Exception_NotFound('Requested page doesn\'t exists'); //it could be a bad request as well } catch (Light_Exception $exception) { throw new Light_Exception('Internal error'); } $this->view->page = $page; }