Пример #1
0
 protected function createResponse($content = '')
 {
     $response = new Buzz\Message\Response();
     $response->addHeader('1.0 200 OK');
     $response->setContent($content);
     return $response;
 }
Пример #2
0
 private function createResponse($content, $statusCode = 200)
 {
     $response = new Response();
     $response->setContent($content);
     $response->setHeaders(array('HTTP/1.1 ' . $statusCode . ' REASON'));
     return $response;
 }
 /**
  * @see Client\ClientInterface
  */
 public function send(Message\Request $request, Message\Response $response)
 {
     if (!($queued = $this->receiveFromQueue())) {
         throw new \LogicException('There are no queued responses.');
     }
     $response->setHeaders($queued->getHeaders());
     $response->setContent($queued->getContent());
 }
Пример #4
0
 public function testGetDomReturnsADomDocument()
 {
     $response = new Message\Response();
     $response->setContent('<html><head></head><body></body></html>');
     $this->browser->getClient()->sendToQueue($response);
     $this->browser->get('http://www.google.com');
     $this->assertTrue($this->browser->getDom() instanceof \DOMDocument);
 }
Пример #5
0
 /**
  * @test
  */
 public function it_translates_a_text()
 {
     $response = new Response();
     $response->setContent('<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">dit is een test</string>');
     $this->browser->expects($this->once())->method('get')->with('http://api.microsofttranslator.com/v2/Http.svc/Translate?from=en&to=nl&text=this+is+a+test')->willReturn($response);
     $translation = $this->translator->translate('en', 'nl', 'this is a test');
     $expectedTranslation = 'dit is een test';
     $this->assertEquals($expectedTranslation, $translation);
 }
Пример #6
0
 /**
  * @return SenderInterface
  */
 private function getSender()
 {
     $client = $this->getMockBuilder('\\Team3\\PayU\\Communication\\Sender\\SenderInterface')->getMock();
     $client->expects($this->any())->method('send')->willReturnCallback(function () {
         $response = new Response();
         $response->setContent(self::RESPONSE_CONTENT);
         return $response;
     });
     return $client;
 }
Пример #7
0
 public function testGetBearerHeaderInvalidTokenTypeException()
 {
     $twitter = $this->getMockBuilder('Endroid\\Twitter\\Twitter')->setConstructorArgs(array('foo', 'bar'))->setMethods(array('getBasicHeader', 'call'))->getMock();
     $twitter->expects($this->any())->method('getBasicHeader')->willReturn(self::EXPECTED_BASIC_HEADER);
     $response = new Response();
     $response->setContent(json_encode(array('token_type' => 'something_wrong', 'access_token' => 'cc4f26cc4a3f61a84436014b2166e431')));
     $twitter->expects($this->any())->method('call')->with('POST', Twitter::BASE_URL . Twitter::TOKEN_URL)->willReturn($response);
     $this->setExpectedException('Endroid\\Twitter\\Exception\\InvalidTokenTypeException');
     Util::invokeMethod($twitter, 'getBearerHeader');
 }
 /**
  * @test
  */
 public function it_should_be_future_proof()
 {
     // google keeps putting more comma's to break peoples implementations
     $response = new Response();
     $response->setContent('[[["What are you doing?","Wat ben jij aan het doen?",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0]],,"nl"]');
     $this->browser->expects($this->once())->method('get')->with('https://translate.googleapis.com/translate_a/single?client=gtx&sl=nl&tl=en&dt=t&q=' . urlencode('Wat ben jij aan het doen?'))->willReturn($response);
     $translation = $this->translator->translate('nl', 'en', 'Wat ben jij aan het doen?');
     $expectedTranslation = 'What are you doing?';
     $this->assertEquals($expectedTranslation, $translation);
 }
Пример #9
0
 protected function getExportResponse()
 {
     $zip = new \ZipArchive();
     $zip->open($this->zipFile, $zip::CREATE);
     $zip->addFile('test/etc/diary.csv', 'diary.csv');
     $zip->close();
     $response = new Response();
     $response->setHeaders(array('HTTP/1.1 200 OK', 'Content-Type: application/zip'));
     $response->setContent(file_get_contents($this->zipFile));
     return $response;
 }
 /**
  * @test
  * @dataProvider getAuthCode
  */
 public function testGetAuthTokenGivenCode($code)
 {
     $response = new Response();
     $response->setContent('{"access_token": "ea135929105c4f29a0f5117d2960926f", "expires_in": 2592000}');
     $response->setHeaders(array('HTTP/1.1 200 OK'));
     $httpClient = $this->getHttpClientMock();
     $httpClient->expects($this->once())->method('post')->with($this->equalTo('https://oauth.yandex.ru/token'), $this->anything(), $this->stringContains($code))->will($this->returnValue($response));
     $auth = new Auth('test', 'test', $httpClient);
     $token = $auth->getAuthToken($code);
     $this->assertInstanceOf('\\Yandex\\Auth\\Token', $token);
     $this->assertEquals($token->getToken(), 'ea135929105c4f29a0f5117d2960926f');
 }
Пример #11
0
    public function testGetStationBoardDelay()
    {
        $response = new Response();
        $response->setContent(file_get_contents(__DIR__ . '/../../fixtures/archive/stationboard-2013-10-15.xml'));
        $this->browser->expects($this->once())->method('post')->with($this->equalTo('http://fahrplan.sbb.ch/bin/extxml.exe/'), $this->equalTo(array('User-Agent: SBBMobile/4.8 CFNetwork/609.1.4 Darwin/13.0.0', 'Accept: application/xml', 'Content-Type: application/xml')), $this->equalTo('<?xml version="1.0" encoding="iso-8859-1"?>
<ReqC lang="EN" prod="iPhone3.1" ver="2.3" accessId="vWjygiRIy0uclbLz4qDO7S3G4dcIIViwoLFCZlopGhe88vlsfedGIqctZP9lvqb"><STBReq boardType="DEP" maxJourneys="40"><Time>22:20</Time><Period><DateBegin><Date>20131015</Date></DateBegin><DateEnd><Date>20131015</Date></DateEnd></Period><TableStation externalId="008591052"/><ProductFilter>1111111111111111</ProductFilter></STBReq></ReqC>
'))->will($this->returnValue($response));
        $station = new Station('008591052');
        // Zürich, Bäckeranlage
        $journeys = $this->api->getStationBoard(new StationBoardQuery($station, \DateTime::createFromFormat(\DateTime::ISO8601, '2013-10-15T22:20:00+01:00')));
        $this->assertEquals(1, count($journeys));
        $this->assertEquals('2013-10-15T22:10:00+0100', $journeys[0]->stop->departure);
        $this->assertEquals(12, $journeys[0]->stop->delay);
    }
Пример #12
0
 public function testUsesTheLastQueuedResponse()
 {
     $response1 = new Message\Response();
     $response1->setContent('first');
     $response2 = new Message\Response();
     $response2->setContent('last');
     $client = new LIFO();
     $client->sendToQueue($response1);
     $client->sendToQueue($response2);
     $request = new Message\Request();
     $response = new Message\Response();
     $client->send($request, $response);
     $this->assertEquals($response->getContent(), 'last');
 }
Пример #13
0
 private function decompressContent(\Buzz\Message\Response $response)
 {
     if (!($content_encoding = $response->getHeader('Content-Encoding'))) {
         return;
     }
     $content = $response->getContent();
     if (strpos($content_encoding, 'deflate') !== false) {
         $content = gzuncompress($content);
     }
     if (strpos($content_encoding, 'gzip') !== false) {
         $content = gzinflate(substr($content, 10));
     }
     $response->setContent($content);
 }
Пример #14
0
 /**
  * @see ClientInterface
  */
 public function send(Message\Request $request, Message\Response $response)
 {
     if ($cookieJar = $this->getCookieJar()) {
         $cookieJar->clearExpiredCookies();
         $cookieJar->addCookieHeaders($request);
     }
     $context = stream_context_create($this->getStreamContextArray($request));
     $content = file_get_contents($request->getUrl(), 0, $context);
     $response->setHeaders($http_response_header);
     $response->setContent($content);
     if ($cookieJar) {
         $cookieJar->processSetCookieHeaders($request, $response);
     }
 }
Пример #15
0
 public function testSetsResponseHeadersAndContent()
 {
     $response = new Message\Response();
     $response->addHeader('HTTP/1.0 200 OK');
     $response->setContent('Hello World!');
     $client = new FIFO();
     $client->setQueue(array($response));
     $client->sendToQueue($response);
     $this->assertEquals(count($client->getQueue()), 2);
     $request = new Message\Request();
     $response = new Message\Response();
     $client->send($request, $response);
     $this->assertEquals(count($client->getQueue()), 1);
     $this->assertEquals($response->getHeaders(), array('HTTP/1.0 200 OK'));
     $this->assertEquals($response->getContent(), 'Hello World!');
 }
Пример #16
0
 /**
  * Test JSON Listener for Buzz
  */
 public function testJsonListener()
 {
     $request = new Request();
     $response = new Response();
     $testJsonArray = ['test1' => 'test2'];
     $testJsonString = json_encode($testJsonArray);
     $response->setContent($testJsonString);
     $listener = new JsonListener();
     $listener->postSend($request, $response);
     /**
      * @var $return \stdClass
      */
     $return = $response->getContent();
     $this->assertObjectHasAttribute('test1', $return);
     $this->assertEquals('test2', $return->test1);
     $this->assertJson(json_encode($return), $testJsonString);
 }
Пример #17
0
 /**
  * @see ClientInterface
  *
  * @throws RuntimeException If file_get_contents() fires an error
  */
 public function send(Message\Request $request, Message\Response $response)
 {
     if ($cookieJar = $this->getCookieJar()) {
         $cookieJar->clearExpiredCookies();
         $cookieJar->addCookieHeaders($request);
     }
     $context = stream_context_create($this->getStreamContextArray($request));
     $content = @file_get_contents($request->getUrl(), 0, $context);
     if (false === $content) {
         $error = error_get_last();
         throw new \RuntimeException($error['message']);
     }
     $response->setHeaders((array) $http_response_header);
     $response->setContent($content);
     if ($cookieJar) {
         $cookieJar->processSetCookieHeaders($request, $response);
     }
 }
 /**
  * @test
  */
 public function testGetHostListUrl()
 {
     $response = new Response();
     $response->setHeaders(array('HTTP/1.1 200 OK'));
     $response->setContent('
         <service>
           <workspace>
             <collection href="https://webmaster.yandex.ru/api/123456789/hosts">
               <title>Host list</title>
             </collection>
           </workspace>
         </service>
     ');
     $httpClient = $this->getHttpClientMock();
     $httpClient->expects($this->once())->method('get')->with($this->equalTo('https://webmaster.yandex.ru/api/123456789'))->will($this->returnValue($response));
     $webmaster = new Webmaster('test', 'test', $httpClient);
     $webmaster->setToken('ea135929105c4f29a0f5117d2960926f');
     $url = $webmaster->getHostListUrl(123456789);
     $this->assertEquals($url, 'https://webmaster.yandex.ru/api/123456789/hosts');
 }
Пример #19
0
 public function testDigestAuthHeader()
 {
     $request = new Message\Request();
     $request->setMethod('GET');
     $request->setResource('/auth-digest');
     $request->setHost('http://test.webdav.org');
     $request->setProtocolVersion('1.1');
     $response = new Message\Response();
     $response->setHeaders(array("Date: Wed, 24 Jun 2015 21:49:39 GMT", "Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.3.2", "WWW-Authenticate: Digest realm=\"test\", nonce=\"5PvRe0oZBQA=874ad6aea3519069f30dfc704e594dde6e01b2a6\", algorithm=MD5, domain=\"/auth-digest/\", qop=\"auth\"", "Content-Length: 401", "Content-Type: text/html; charset=iso-8859-1"));
     $response->setContent("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>401 Authorization Required</title>\n</head><body>\n<h1>Authorization Required</h1>\n<p>This server could not verify that you\nare authorized to access the document\nrequested.  Either you supplied the wrong\ncredentials (e.g., bad password), or your\nbrowser doesn\\'t understand how to supply\nthe credentials required.</p>\n</body></html>");
     // Simulate the First Request/Response, where the server returns 401
     $listener = new DigestAuthListener('user1', 'user1');
     $listener->preSend($request);
     $listener->postSend($request, $response);
     // Simulate sending the second Request using the calculated Authorization Header
     $request = new Message\Request();
     $request->setMethod('GET');
     $request->setResource('/auth-digest');
     $request->setHost('http://test.webdav.org');
     $request->setProtocolVersion('1.1');
     $this->assertEmpty($request->getHeader('Authorization'));
     $listener->preSend($request);
     $this->assertEquals('Digest username="******", realm="test", nonce="5PvRe0oZBQA=874ad6aea3519069f30dfc704e594dde6e01b2a6", response="b2cf05a5d3f51d84a8866309aed6cb5d", uri="/auth-digest"', $request->getHeader('Authorization'));
 }
Пример #20
0
 /**
  * @dataProvider getUrls
  */
 public function testTransformWithUrl($url)
 {
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_youtube.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('Nono le petit robot', $media->getName(), '::getName() return the file name');
     $this->assertSame('BDYAbAtaDzA', $media->getProviderReference(), '::getProviderReference() is set');
 }
 public function testTransformWithUrl()
 {
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_dailymotion.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => null, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent('http://www.dailymotion.com/video/x9wjql_asdasdasdsa_asdsds');
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertEquals('Thomas Rabaix - les tests fonctionnels - Symfony Live 2009', $media->getName(), '::getName() return the file name');
     $this->assertEquals('x9wjql', $media->getProviderReference(), '::getProviderReference() is set');
 }
    /**
     * Create new Response.
     *
     * @param string $status  response status description
     * @param string $content content
     *
     * @return Message\Response
     */
    protected function createResponse($status, $content = null)
    {
        $response = new Message\Response();
        $response->addHeader($status);

        if (null !== $content) {
            $response->setContent($content);
        }

        return $response;
    }
Пример #23
0
 private function getMockInvalidResponse()
 {
     $response = new Response();
     $response->setContent('<?not_valid_xml<');
     return $response;
 }
 /**
  * @dataProvider getUrls
  */
 public function testTransformWithUrl($url)
 {
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_sapo.txt'));
     $browser->expects($this->at(0))->method('get')->will($this->returnValue($response));
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_sapo_html.txt'));
     $browser->expects($this->at(1))->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('Inferno T5 :: PROMO Ep.106', $media->getName(), '::getName() return the file name');
     $this->assertSame('4MyqjpF3WWNpiTCvNJ60', $media->getProviderReference(), '::getProviderReference() is set');
 }
Пример #25
0
 private function createResponse($statusCode = 200, $content = true)
 {
     $response = new Response();
     $response->setHeaders(array(sprintf("HTTP/1.1 %s FOOBAR", $statusCode)));
     if ($content) {
         $response->setContent($this->xml);
     }
     return $response;
 }
Пример #26
0
 /**
  * @dataProvider getTransformWithUrlMedia
  */
 public function testTransformWithUrl($media)
 {
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_vimeo.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     // pre persist the media
     $provider->transform($media);
     $provider->prePersist($media);
     $this->assertSame('Blinky™', $media->getName(), '::getName() return the file name');
     $this->assertSame('012341231', $media->getProviderReference(), '::getProviderReference() is set');
 }
 /**
  * Driver should throw an Exception if response does not have either result or error set.
  */
 public function testCallWithoutErrorOrResult()
 {
     $this->expectException(InvalidResponseException::class);
     $httpResponse = new HttpResponse();
     $httpResponse->setContent('{"jsonrpc": "2.0"}');
     $this->expectHttpRequest($this->anything(), $this->anything(), $this->anything(), $this->anything(), $httpResponse);
     $this->driver->call($this->location, $this->createRequest())->resolve();
 }
 function it_does_not_remove_an_already_completed_accreditation_process(Browser $browser)
 {
     $this->beConstructedWith('a-key', 'foo.bar', $browser);
     $response = new Response();
     $response->setContent(json_encode(array('response' => 'failure', 'reason' => 'This request has already been completed')));
     $browser->get('foo.bar/removeRequest.php?key=a-key&id=123')->willReturn($response);
     $this->remove('123')->shouldBeLike(new FailureResponse(FailureResponse::REASON_COMPLETED));
 }
Пример #29
0
    /**
     * @return Response
     */
    private function getOrderStatusCurlResponse()
    {
        $response = new Response();
        $response->setContent('{
        "orders": [
            {
                "orderId": "' . self::ORDER_ID . '",
                "extOrderId": "' . self::EXT_ORDER_ID . '",
                "orderCreateDate": "2014-10-27T14:58:17.443+01:00",
                "notifyUrl": "http://localhost/OrderNotify/",
                "customerIp": "127.0.0.1",
                "merchantPosId": "145227",
                "description": "New order",
                "currencyCode": "PLN",
                "totalAmount": "3200",
                "status": "' . self::ORDER_STATUS . '",
                "products": [
                    {
                        "name": "Product1",
                        "unitPrice": "1000",
                        "quantity": "1"
                    },
                    {
                        "name": "Product2",
                        "unitPrice": "2200",
                        "quantity": "1"
                    }
                ]
            }
        ],
        "status": {
            "statusCode": "SUCCESS",
            "statusDesc": "Request processing successful"
        }
}');
        return $response;
    }
 /**
  * dataProvider getUrls
  */
 public function testTransformWithUrl($url = null)
 {
     return;
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_playwire.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('Quanto é um trilião elevado a 10?', $media->getName(), '::getName() return the file name');
     $this->assertSame('1000748|4517915', $media->getProviderReference(), '::getProviderReference() is set');
 }