public function testHandleUncaughtException()
 {
     $requestInfo = new RequestInfo(['REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/domain/ice_hawk_read']);
     $routeRequest = new RouteRequest($requestInfo->getUri(), $requestInfo->getMethod());
     $requestData = new WriteRequest($requestInfo, new WriteRequestInput('', []));
     try {
         $unresolvedRequest = (new UnresolvedRequest())->withDestinationInfo($routeRequest);
         $responder = new FinalWriteResponder();
         $responder->handleUncaughtException($unresolvedRequest, $requestData);
         $this->fail('No Exception thrown');
     } catch (UnresolvedRequest $ex) {
         $this->assertSame($routeRequest, $ex->getDestinationInfo());
     } catch (\Throwable $throwable) {
         $this->fail('Wrong exception thrown');
     }
 }
 public function testCanRetrieveInjectedObjects()
 {
     $requestInfo = RequestInfo::fromEnv();
     $requestInput = new ReadRequestInput([]);
     $readRequest = new ReadRequest($requestInfo, $requestInput);
     $event = new HandlingReadRequestEvent($readRequest);
     $this->assertSame($requestInfo, $event->getRequestInfo());
     $this->assertSame($requestInput, $event->getRequestInput());
 }
 public function testCanRetrieveInjectedObjects()
 {
     $requestInfo = RequestInfo::fromEnv();
     $requestInput = new WriteRequestInput('', []);
     $writeRequest = new WriteRequest($requestInfo, $requestInput);
     $event = new WriteRequestWasHandledEvent($writeRequest);
     $this->assertSame($requestInfo, $event->getRequestInfo());
     $this->assertSame($requestInput, $event->getRequestInput());
 }
Example #4
0
 public function testDefaults()
 {
     $config = new IceHawkConfig();
     $this->assertEquals([], $config->getEventSubscribers());
     $this->assertEquals(RequestInfo::fromEnv(), $config->getRequestInfo());
     $this->assertEquals(new FinalReadResponder(), $config->getFinalReadResponder());
     $this->assertEquals(new FinalWriteResponder(), $config->getFinalWriteResponder());
     $this->assertEquals([], $config->getWriteRoutes());
     $this->assertEquals([], $config->getReadRoutes());
 }
Example #5
0
 public function testPublishesEventWhenInitializationIsDone()
 {
     $requestInfo = RequestInfo::fromEnv();
     $initializingEvent = new InitializingIceHawkEvent($requestInfo);
     $initializedEvent = new IceHawkWasInitializedEvent($requestInfo);
     $eventListener = $this->getMockBuilder(SubscribesToEvents::class)->setMethods(['acceptsEvent', 'notify'])->getMockForAbstractClass();
     $eventListener->expects($this->at(0))->method('acceptsEvent')->with($this->equalTo($initializingEvent))->willReturn(true);
     $eventListener->expects($this->at(1))->method('notify')->with($this->equalTo($initializingEvent));
     $eventListener->expects($this->at(2))->method('acceptsEvent')->with($this->equalTo($initializedEvent))->willReturn(true);
     $eventListener->expects($this->at(3))->method('notify')->with($this->equalTo($initializedEvent));
     $config = $this->getMockBuilder(ConfiguresIceHawk::class)->getMockForAbstractClass();
     $config->expects($this->once())->method('getRequestInfo')->willReturn($requestInfo);
     $config->expects($this->once())->method('getEventSubscribers')->willReturn([$eventListener]);
     $iceHawk = new IceHawk($config, new IceHawkDelegate());
     $iceHawk->init();
 }
 public function testCanRetrieveInjectedObjects()
 {
     $requestInfo = RequestInfo::fromEnv();
     $event = new IceHawkWasInitializedEvent($requestInfo);
     $this->assertSame($requestInfo, $event->getRequestInfo());
 }
Example #7
0
 public function testHttpsIsCheckedCaseInsensitive()
 {
     $requestInfo1 = new RequestInfo(['HTTPS' => 'On']);
     $requestInfo2 = new RequestInfo(['HTTPS' => 'on']);
     $requestInfo3 = new RequestInfo(['HTTPS' => 'oN']);
     $requestInfo4 = new RequestInfo(['HTTPS' => 'ON']);
     $this->assertTrue($requestInfo1->isSecure());
     $this->assertTrue($requestInfo2->isSecure());
     $this->assertTrue($requestInfo3->isSecure());
     $this->assertTrue($requestInfo4->isSecure());
 }
 public function getRequestInfo() : ProvidesRequestInfo
 {
     return RequestInfo::fromEnv();
 }