/** * @param \Ratchet\ConnectionInterface $conn * @param \Guzzle\Http\Message\RequestInterface $request null is default because PHP won't let me overload; don't pass null!!! * @throws \UnexpectedValueException if a RequestInterface is not passed */ public function onOpen(ConnectionInterface $conn, \Guzzle\Http\Message\RequestInterface $request = null) { $response = new \Guzzle\Http\Message\Response(200); $response->setBody(file_get_contents($this->path)); $conn->send($response); $conn->close(); }
public function testEventOnErrorRequest() { // prepare response $response = new \Guzzle\Http\Message\Response(404); $response->setBody(json_encode(array('error' => 0))); // replace response $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $plugin->addResponse($response); // configure subscriber $factory = new Factory('http://localhost/'); $factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock'); $request = $factory->createRequest('GetRequestMock'); $request->addSubscriber($plugin); $callStack = array(); // configure event $request->onBeforeSend(function (\Guzzle\Common\Event $e) use(&$callStack) { $callStack[] = 'before_send'; })->onSend(function (\Guzzle\Common\Event $e) use(&$callStack) { $callStack[] = 'send'; })->onCompleteSend(function (\Guzzle\Common\Event $e) use(&$callStack) { $callStack[] = 'complete'; })->onError(function (\Guzzle\Common\Event $e) use(&$callStack) { $callStack[] = 'error'; })->onSuccess(function (\Guzzle\Common\Event $e) use(&$callStack) { $callStack[] = 'success'; }); try { $response = $request->send(); $this->assertFalse($response); } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) { } $this->assertEquals(array('before_send', 'send', 'complete', 'error'), $callStack); }
private function initBitlyClient($data) { $bitlyResponse = new \Guzzle\Http\Message\Response(200); $bitlyResponse->setBody($data); $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $plugin->addResponse($bitlyResponse); $this->bitly_client->addSubscriber($plugin); }
private function createPackagistClient($data, $status = 200) { $packagistResponse = new \Guzzle\Http\Message\Response($status); $packagistResponse->setBody($data); $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $plugin->addResponse($packagistResponse); $clientHttp = new \Guzzle\Http\Client(); $clientHttp->addSubscriber($plugin); return new Client($clientHttp); }
/** * @return \Guzzle\Http\Client */ protected function buildHttpMockClient($body) { $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $response = new \Guzzle\Http\Message\Response(200); $response->setBody($body); $plugin->addResponse($response); $mockedClient = new \Guzzle\Http\Client(); $mockedClient->addSubscriber($plugin); return $mockedClient; }
/** * @param \Acquia\Network\AcquiaNetworkClient $network * @param string $responseFile */ public function addMockResponse(AcquiaNetworkClient $network, $responseFile, $responseCode) { $mock = new \Guzzle\Plugin\Mock\MockPlugin(); $response = new \Guzzle\Http\Message\Response($responseCode); if (is_string($responseFile)) { $response->setBody(file_get_contents($responseFile)); } $mock->addResponse($response); $network->addSubscriber($mock); }
public function setUp() { // see the config_test.yml, there's a parameters in order to not stream the output using FakeImageCreator. $data = '{"package":{"name":"pugx\\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","time":"2013-05-24T14:45:06+00:00","maintainers":[{"name":"liuggio","email":"*****@*****.**"}],"versions":{"dev-master":{"name":"pugx\\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","keywords":[],"homepage":"","version":"dev-master","version_normalized":"9999999-dev","license":[],"authors":[],"source":{"type":"git","url":"https:\\/\\/github.com\\/PUGX\\/badge-poser.git","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e"},"dist":{"type":"zip","url":"https:\\/\\/api.github.com\\/repos\\/PUGX\\/badge-poser\\/zipball\\/024df1d420cd715aea3400bfea9b87ed0f3bb47e","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e","shasum":""},"type":"library","time":"2013-05-24T19:19:25+00:00","autoload":{"psr-0":{"":"src\\/"}},"extra":{"symfony-app-dir":"app","symfony-web-dir":"web","branch-alias":{"dev-master":"0.1-dev"}},"require":{"php":">=5.3.3","symfony\\/symfony":"2.2.*","doctrine\\/orm":">=2.2,<3.0,>=2.2.3","doctrine\\/doctrine-bundle":"1.2.*","twig\\/extensions":"1.0.*","symfony\\/assetic-bundle":"2.1.*","symfony\\/swiftmailer-bundle":"2.2.*","symfony\\/monolog-bundle":"2.2.*","sensio\\/distribution-bundle":"2.2.*","sensio\\/framework-extra-bundle":"2.2.*","sensio\\/generator-bundle":"2.2.*","jms\\/security-extra-bundle":"1.4.*","jms\\/di-extra-bundle":"1.3.*","knplabs\\/packagist-api":"dev-master"},"require-dev":{"guzzle\\/plugin-mock":"*"}},"dev-develop":{"name":"pugx\\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","keywords":[],"homepage":"","version":"dev-develop","version_normalized":"dev-develop","license":[],"authors":[],"source":{"type":"git","url":"https:\\/\\/github.com\\/PUGX\\/badge-poser.git","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e"},"dist":{"type":"zip","url":"https:\\/\\/api.github.com\\/repos\\/PUGX\\/badge-poser\\/zipball\\/024df1d420cd715aea3400bfea9b87ed0f3bb47e","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e","shasum":""},"type":"library","time":"2013-05-24T19:19:25+00:00","autoload":{"psr-0":{"":"src\\/"}},"extra":{"symfony-app-dir":"app","symfony-web-dir":"web","branch-alias":{"dev-master":"0.1-dev"}},"require":{"php":">=5.3.3","symfony\\/symfony":"2.2.*","doctrine\\/orm":">=2.2,<3.0,>=2.2.3","doctrine\\/doctrine-bundle":"1.2.*","twig\\/extensions":"1.0.*","symfony\\/assetic-bundle":"2.1.*","symfony\\/swiftmailer-bundle":"2.2.*","symfony\\/monolog-bundle":"2.2.*","sensio\\/distribution-bundle":"2.2.*","sensio\\/framework-extra-bundle":"2.2.*","sensio\\/generator-bundle":"2.2.*","jms\\/security-extra-bundle":"1.4.*","jms\\/di-extra-bundle":"1.3.*","knplabs\\/packagist-api":"dev-master"},"require-dev":{"guzzle\\/plugin-mock":"*"}}},"type":"library","repository":"https:\\/\\/github.com\\/PUGX\\/badge-poser","downloads":{"total":99,"monthly":12,"daily":9},"favers":9}}'; $packagistResponse = new \Guzzle\Http\Message\Response(200); $packagistResponse->setBody($data); $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $plugin->addResponse($packagistResponse); $clientHttp = new \Guzzle\Http\Client(); $clientHttp->addSubscriber($plugin); $this->packagistClient = new Client($clientHttp); }
/** * @expectedException \OutOfBoundsException */ public function testNestedCollectionNotFound() { $data = array('invalidProperty' => array(array('name' => 'value1'))); $response = new \Guzzle\Http\Message\Response(200); $response->setBody(Json::encode($data)); $mock = new \Guzzle\Plugin\Mock\MockPlugin(); $mock->addResponse($response); $client = new Client('http://example.com'); $client->addSubscriber($mock); $request = $client->get('/test'); $collection = new DummyCollection($request); foreach ($collection as $element) { // We should never get here ... } }
public function testGetStat() { $factory = new \Sokil\DistributiveManager('http://dl.local/'); $factory->setAppId('5368e18efb5d1b1b2fa3a97d')->setAppKey('awlxWpJ2CiOzorQQYHkx0s3BI4ZjjlnB7yJNq7nk'); /* @var $request \Sokil\DistributiveManager\Request\DownloadStat */ $request = $factory->createRequest('downloadStat', array('environment_name' => 'windows')); // prepare response mock $responseMock = new \Guzzle\Http\Message\Response(200); $responseMock->setBody(json_encode(array('stat' => array('windows' => array('1399493561' => 20, '1399493562' => 8), 'android' => array('1399493563' => 20, '1399493564' => 8)), 'total' => 28))); $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $plugin->addResponse($responseMock); $request->addSubscriber($plugin); // send request $response = $request->send(); // check response $this->assertEquals(200, $response->getHttpCode()); $this->assertEquals(28, $response->getTotalDownloads()); $this->assertEquals(array('windows' => array('1399493561' => 20, '1399493562' => 8), 'android' => array('1399493563' => 20, '1399493564' => 8)), $response->getStatList()); $this->assertEquals(array('1399493561' => 20, '1399493562' => 8), $response->getEnvironmentStat('windows')); }
/** * @expectedException \Tufesa\Service\Exceptions\ResponseException */ public function test_buy_a_ticket_with_invalid_data_should_raise_an_exception_work() { $response = new \Guzzle\Http\Message\Response(200); $response->setBody('{"_id": "1.0", "_Response": { "_revAuth": null, "resultField": { "_id": "666", "_message": "SOME DUMMY MESSAGE HERE" }}}'); $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $plugin->addResponse($response); $guzzleClient = new GuzzleClient(); $guzzleClient->addSubscriber($plugin); $tufesaClient = new Client($guzzleClient); $requestData = ["from" => "GDL", "to" => "OBR", "date" => "20140720", "schedule" => 123456789, "folio" => 123456789, "customers" => [["name" => "Juan Perez", "category" => "C", "seat" => 8]]]; $buyRequest = BuyRequestFactory::create($requestData); $buyResponse = $tufesaClient->buyTickets($buyRequest); $this->assertInstanceOf('Tufesa\\Service\\Type\\BuyResponse', $buyResponse); }
public function testGetResponseDataException() { $this->setExpectedException('Exception'); $mockResponse = new \Guzzle\Http\Message\Response(200); $mockResponse->setBody('simple text', 'application/text'); $this->setPropertyValue('response', $mockResponse); $this->obj->getResponseData(); }