Source of file BootstrapTest.php
Size: 3,779 Bytes - Last Modified: 2021-12-24T06:51:36+00:00
/var/www/docs.ssmods.com/process/src/tests/BootstrapTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 | <?php namespace Heystack\Core; class BootstrapTest extends \PHPUnit_Framework_TestCase { protected $container; public function setUp() { $this->container = $this->getMock( 'Heystack\Core\DependencyInjection\SilverStripe\HeystackSilverStripeContainer' ); } /** * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getSessionMock() { return $this->getMockBuilder('Session') ->disableOriginalConstructor() ->getMock(); } /** * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getRequestMock() { return $this->getMockBuilder('SS_HTTPrequest') ->disableOriginalConstructor() ->getMock(); } /** * @covers \Heystack\Core\Bootstrap::__construct */ public function testCanConstructWithValidArguments() { $this->assertTrue( is_object( new Bootstrap($this->container) ) ); } /** * @covers \Heystack\Core\Bootstrap::__construct * @covers \Heystack\Core\Bootstrap::preRequest * @covers \Heystack\Core\Bootstrap::doBootstrap */ public function testPreRequestDoesBootstrap() { $session = $this->getSessionMock(); $sessionBackend = $this->getMock( 'Heystack\Core\State\Backends\Session' ); $eventDispatcher = $this->getMock( 'Heystack\Core\EventDispatcher' ); $sessionBackend ->expects($this->once()) ->method('setSession') ->with($session); $eventDispatcher ->expects($this->once()) ->method('dispatch') ->with(Events::PRE_REQUEST); $this->container ->expects($this->at(0)) ->method('get') ->with(Services::BACKEND_SESSION) ->will($this->returnValue($sessionBackend)); $this->container ->expects($this->at(1)) ->method('get') ->with(Services::EVENT_DISPATCHER) ->will($this->returnValue($eventDispatcher)); (new Bootstrap($this->container))->preRequest( $this->getRequestMock(), $session, $this->getMock('DataModel') ); } /** * @covers \Heystack\Core\Bootstrap::__construct * @covers \Heystack\Core\Bootstrap::postRequest * @covers \Heystack\Core\Bootstrap::doBootstrap */ public function testPostRequestDoesDispatch() { $session = $this->getSessionMock(); $sessionBackend = $this->getMock( 'Heystack\Core\State\Backends\Session' ); $eventDispatcher = $this->getMock( 'Heystack\Core\EventDispatcher' ); $sessionBackend ->expects($this->once()) ->method('setSession') ->with($session); $eventDispatcher ->expects($this->once()) ->method('dispatch') ->with(Events::POST_REQUEST); $this->container ->expects($this->at(0)) ->method('get') ->with(Services::BACKEND_SESSION) ->will($this->returnValue($sessionBackend)); $this->container ->expects($this->at(1)) ->method('get') ->with(Services::EVENT_DISPATCHER) ->will($this->returnValue($eventDispatcher)); $b = new Bootstrap($this->container); $b->doBootstrap($session); $b->postRequest( $this->getRequestMock(), $this->getMock('SS_HTTPResponse'), $this->getMock('DataModel') ); } } |