Source of file RequestTest.php
Size: 3,398 Bytes - Last Modified: 2021-12-24T06:51:27+00:00
/var/www/docs.ssmods.com/process/src/tests/Input/RequestTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 | <?php namespace Heyday\SilverStripe\WkHtml\Input; use Heyday\SilverStripe\WkHtml\EchoValue; use SilverStripe\Control\Director; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\Session; use SilverStripe\Dev\SapphireTest; class RequestTest extends SapphireTest { /** * @var Request */ protected $object; /** * @var \ReflectionMethod|\PHPUnit_Framework_MockObject_MockObject */ protected $handleMethod; /** * @var HTTPRequest|\PHPUnit_Framework_MockObject_MockObject */ protected $request; /** * */ public function testSetSessionException() { $this->expectException(\RuntimeException::class); $this->object->setSession('test'); } public function testSetSessionSession() { /** @var Session $session */ $session = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->getMock(); $this->object->setSession($session); $this->assertEquals($session, $this->object->getSession()); } public function testSetSessionArray() { $this->object->setSession([]); $this->assertEquals(new Session([]), $this->object->getSession()); } public function testProcessString() { $this->handleMethod ->expects($this->any()) ->method('invoke') ->will($this->returnValue('test')); $this->object->setHandleMethod($this->getHandleMethodCallable()); $this->assertEquals('test', $this->object->process()); } /** * @return \Closure */ protected function getHandleMethodCallable() { return function (HTTPRequest $request) { return $this->handleMethod->invoke(Director::singleton(), $request); }; } public function testProcessResponse() { $response = $this->createMock(HTTPResponse::class); $response->expects($this->any()) ->method('output') ->will(new EchoValue('test')); $this->handleMethod->expects($this->any()) ->method('invoke') ->will($this->returnValue($response)); $this->object->setHandleMethod($this->getHandleMethodCallable()); $this->assertEquals('test', $this->object->process()); } /** * */ public function testProcessBadReturn() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage("Can't handle output from request"); $this->handleMethod->expects($this->any()) ->method('invoke') ->will($this->returnValue([])); $this->object->setHandleMethod($this->getHandleMethodCallable()); $this->assertEquals('test', $this->object->process()); } /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { parent::setUp(); $this->request = $this->getMockBuilder(HTTPRequest::class) ->disableOriginalConstructor() ->getMock(); $this->handleMethod = $this->getMockBuilder(\ReflectionMethod::class) ->disableOriginalConstructor() ->getMock(); $this->object = Request::create($this->request); } } |