コード例 #1
0
ファイル: App.php プロジェクト: rockeinstein/library
 public function run()
 {
     try {
         $response = $this->tryRun();
     } catch (\Exception $ex) {
         $response = new \Zend\Http\Response();
         $code = $ex->getCode();
         if (is_numeric($code) && $code >= 200 && $code <= 500) {
             $response->setStatusCode($code);
         } else {
             $response->setStatusCode(500);
         }
         $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
         $response->setContent(\json_encode(array('exception' => get_class($ex), 'message' => $ex->getMessage())));
     }
     $response->getHeaders()->addHeaderLine('Access-Control-Allow-Origin', '*');
     /**
      * Imprime a resposta
      */
     $status = $response->renderStatusLine();
     header($status);
     foreach ($response->getHeaders() as $header) {
         if ($header instanceof MultipleHeaderInterface) {
             header($header->toString(), false);
             continue;
         }
         header($header->toString());
     }
     echo $response->getContent();
 }
 public function testHandleResponseWithErrorStatusCode()
 {
     $this->setExpectedException('InoOicClient\\Oic\\Exception\\HttpErrorStatusException');
     $httpResponse = new \Zend\Http\Response();
     $httpResponse->setStatusCode(500);
     $this->handler->handleResponse($httpResponse);
 }
 public function testHandleResponseWithServerError()
 {
     $httpResponse = new \Zend\Http\Response();
     $httpResponse->setStatusCode(401);
     $httpResponse->getHeaders()->addHeaders(array('WWW-Authenticate' => 'Bearer error="server_error",foo="bar"'));
     $this->handler->handleResponse($httpResponse);
     $this->assertTrue($this->handler->isError());
     $error = $this->handler->getError();
     $this->assertInstanceOf('InoOicClient\\Oic\\Error', $error);
     $this->assertSame('server_error', $error->getCode());
 }
コード例 #4
0
ファイル: ReaderTest.php プロジェクト: bradley-holt/zf2
 /**
  * @group ZF-8330
  */
 public function testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath()
 {
     try {
         $currClient = Reader\Reader::getHttpClient();
         $response = new \Zend\Http\Response();
         $response->setContent('<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>');
         $response->setStatusCode(200);
         $testAdapter = new \Zend\Http\Client\Adapter\Test();
         $testAdapter->setResponse($response);
         Reader\Reader::setHttpClient(new \Zend\Http\Client(null, array('adapter' => $testAdapter)));
         $links = Reader\Reader::findFeedLinks('http://foo/bar');
         Reader\Reader::setHttpClient($currClient);
     } catch (\Exception $e) {
         $this->fail($e->getMessage());
     }
     $this->assertEquals('http://foo/test.rss', $links->rss);
     $this->assertEquals('http://foo/test.atom', $links->atom);
 }
コード例 #5
0
 /**
  * Test unsuccessful query
  *
  * @return void
  *
  * @expectedException        VuFind\Exception\Mail
  * @expectedExceptionMessage Problem sending text.
  */
 public function testFailureResponse()
 {
     $client = $this->getMockClient();
     $expectedUri = 'https://api.clickatell.com/http/sendmsg?api_id=api_id&user=user&password=password&to=1234567890&text=hello';
     $response = new \Zend\Http\Response();
     $response->setStatusCode(404);
     $client->expects($this->once())->method('setMethod')->with($this->equalTo('GET'))->will($this->returnValue($client));
     $client->expects($this->once())->method('setUri')->with($this->equalTo($expectedUri))->will($this->returnValue($client));
     $client->expects($this->once())->method('send')->will($this->returnValue($response));
     $obj = $this->getClickatell($client);
     $obj->text('Clickatell', '1234567890', '*****@*****.**', 'hello');
 }
コード例 #6
0
 public function testImportActionPostValidSuccess()
 {
     $fileSpec = array('tmp_name' => 'uploaded_file');
     $this->getRequest()->getFiles()->set('File', $fileSpec);
     $postData = array('key' => 'value');
     $form = $this->getApplicationServiceLocator()->get('FormElementManager')->get('Console\\Form\\Import');
     $form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $form->expects($this->once())->method('setData')->with(array('File' => $fileSpec, 'key' => 'value'));
     $form->expects($this->once())->method('getData')->will($this->returnValue(array('File' => $fileSpec)));
     $form->expects($this->never())->method('render');
     $response = new \Zend\Http\Response();
     $response->setStatusCode(200);
     $this->_inventoryUploader->expects($this->once())->method('uploadFile')->with('uploaded_file')->will($this->returnValue($response));
     $this->dispatch('/console/client/import/', 'POST', $postData);
     $this->assertRedirectTo('/console/client/index/');
 }