예제 #1
0
파일: HttpServer.php 프로젝트: marcj/php-pm
 public function handleRequest(ConnectionInterface $conn, Request $request, $bodyBuffer)
 {
     $response = new HttpResponse($conn);
     $response->on('close', array($request, 'close'));
     if (!$this->listeners('request')) {
         $response->end();
         return;
     }
     $this->emit('request', array($request, $response));
     $request->emit('data', array($bodyBuffer));
 }
예제 #2
0
 /** @test */
 public function requestsShouldTriggersGloubsterCallbacksWithAGoodJob()
 {
     $reactor = $this->getReactSocketServerMock();
     $server = new HttpServer($reactor);
     $handler = $this->getMessageHandlerMock();
     $handler->expects($this->once())->method('receive')->with($this->equalTo('GOOD MESSAGE'))->will($this->returnValue(true));
     $httpListener = new HTTPListener($server, $reactor, $this->getLogger());
     $httpListener->attach($handler);
     $httpListener->listen();
     $request = new HttpRequest('GET', '/');
     $response = $this->getReactHttpResponseMock();
     $phpunit = $this;
     $catch = false;
     $response->expects($this->once())->method('write')->will($this->returnCallback(function ($json) use($phpunit, &$catch) {
         $catch = true;
         $ack = MessageFactory::fromJson($json);
         $phpunit->assertInstanceOf('Gloubster\\Message\\Acknowledgement\\JobAcknowledgement', $ack);
     }));
     $server->emit('request', array($request, $response));
     $request->emit('data', array('GOOD ME'));
     $request->emit('data', array('SSAGE'));
     $request->emit('end', array());
 }
예제 #3
0
 /** @test */
 public function requestsShouldTriggersGloubsterErrorCallback()
 {
     $exception = new \Exception('This is an exception');
     $reactor = $this->getReactSocketServerMock();
     $server = new HttpServer($reactor);
     $handler = $this->getMessageHandlerMock();
     $handler->expects($this->once())->method('error')->with($this->equalTo($exception));
     $httpListener = new HTTPListener($server, $reactor, $this->getLogger());
     $httpListener->attach($handler);
     $httpListener->listen();
     $request = new \React\Http\Request('GET', '/');
     $response = $this->getReactHttpResponseMock();
     $server->emit('request', array($request, $response));
     $request->emit('error', array($exception));
 }