public function testEmitspuzzle_event_HeadersEventForHeadRequest() { puzzle_test_Server::enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK")); $this->_closure_testEmitspuzzle_event_HeadersEventForHeadRequest_ee = null; $client = new puzzle_Client(array('adapter' => new puzzle_adapter_curl_MultiAdapter(new puzzle_message_MessageFactory()))); $client->head(puzzle_test_Server::$url, array('events' => array('headers' => array($this, '__callback_testEmitspuzzle_event_HeadersEventForHeadRequest')))); $this->assertInstanceOf('puzzle_event_HeadersEvent', $this->_closure_testEmitspuzzle_event_HeadersEventForHeadRequest_ee); }
public function testStripsFragmentFromHost() { puzzle_test_Server::flush(); puzzle_test_Server::enqueue("HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n"); // This will fail if the removal of the #fragment is not performed $url = puzzle_Url::fromString(puzzle_test_Server::$url)->setPath(null)->setFragment('foo'); $client = new puzzle_Client(); $client->get($url); }
/** * @dataProvider hasBodyProvider */ public function testSendsWithBody($method) { puzzle_test_Server::flush(); puzzle_test_Server::enqueue(array(new puzzle_message_Response(200))); call_user_func("puzzle_{$method}", puzzle_test_Server::$url, array('headers' => array('foo' => 'bar'), 'body' => 'test', 'query' => array('a' => '1'))); $rx = puzzle_test_Server::received(true); $sent = $rx[0]; $this->assertEquals(strtoupper($method), $sent->getMethod()); $this->assertEquals('/?a=1', $sent->getResource()); $this->assertEquals('bar', $sent->getHeader('foo')); $this->assertEquals('test', $sent->getBody()); }
private static function getClient() { if (!self::$client) { self::$client = new puzzle_Client(array('base_url' => self::$url)); } return self::$client; }
public function testReleasesAdditionalEasyHandles() { puzzle_test_Server::flush(); puzzle_test_Server::enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")); $a = new puzzle_adapter_curl_CurlAdapter(new puzzle_message_MessageFactory(), array('max_handles' => 2)); $this->_closure_testReleasesAdditionalEasyHandles_client = new puzzle_Client(array('base_url' => puzzle_test_Server::$url, 'adapter' => $a)); $request = $this->_closure_testReleasesAdditionalEasyHandles_client->createRequest('GET', '/', array('events' => array('headers' => array($this, '__callback_testReleasesAdditionalEasyHandles_1')))); $transaction = new puzzle_adapter_Transaction($this->_closure_testReleasesAdditionalEasyHandles_client, $request); $a->send($transaction); $this->assertCount(2, $this->readAttribute($a, 'handles')); }
public function testThrowsImmediatelyWhenInstructed() { puzzle_test_Server::flush(); puzzle_test_Server::enqueue(array("HTTP/1.1 501\r\nContent-Length: 0\r\n\r\n")); $c = new puzzle_Client(array('base_url' => puzzle_test_Server::$url)); $request = $c->createRequest('GET', '/'); $request->getEmitter()->on('error', array($this, '__callback_testThrowsImmediatelyWhenInstructed')); $transactions = array(new puzzle_adapter_Transaction($c, $request)); $a = new puzzle_adapter_curl_MultiAdapter(new puzzle_message_MessageFactory()); try { $a->sendAll(new ArrayIterator($transactions), 1); $this->fail('Did not throw'); } catch (puzzle_exception_RequestException $e) { $this->assertSame($request, $e->getRequest()); } }
public function testDoesNotAlwaysAddContentType() { puzzle_test_Server::flush(); puzzle_test_Server::enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")); $client = new puzzle_Client(); $client->put(puzzle_test_Server::$url . '/foo', array('body' => 'foo')); $rx = puzzle_test_Server::received(true); $request = $rx[0]; $this->assertEquals('', $request->getHeader('Content-Type')); }
function __shutdown_puzzle_tests() { if (puzzle_test_Server::$started) { puzzle_test_Server::stop(); } }
public function testDoesNotAddContentTypeByDefault() { puzzle_test_Server::flush(); puzzle_test_Server::enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"); $client = new puzzle_Client(array('base_url' => puzzle_test_Server::$url, 'adapter' => new puzzle_adapter_StreamAdapter(new puzzle_message_MessageFactory()))); $client->put('/', array('body' => 'foo')); $requests = puzzle_test_Server::received(true); $this->assertEquals('', $requests[0]->getHeader('Content-Type')); $this->assertEquals(3, $requests[0]->getHeader('Content-Length')); }
<?php /* * Runs a performance test against the node.js server for both serial and * parallel requests. Requires PHP 5.5 or greater. * * # Basic usage * make perf * # With custom options * REQUESTS=100 PARALLEL=5000 make perf */ require dirname(__FILE__) . '/bootstrap.php'; // Wait until the server is responding puzzle_test_Server::wait(); // Get custom make variables $total = isset($_SERVER['REQUESTS']) ? $_SERVER['REQUESTS'] : 1000; $parallel = isset($_SERVER['PARALLEL']) ? $_SERVER['PARALLEL'] : 25; $client = new puzzle_Client(array('base_url' => puzzle_test_Server::$url)); $t = microtime(true); for ($i = 0; $i < $total; $i++) { $client->get('/guzzle-server/perf'); } $totalTime = microtime(true) - $t; $perRequest = $totalTime / $total * 1000; printf("Serial: %f (%f ms / request) %d total\n", $totalTime, $perRequest, $total); // Create a generator used to yield batches of requests to sendAll $reqs = function () use($client, $total) { for ($i = 0; $i < $total; $i++) { (yield $client->createRequest('GET', '/guzzle-server/perf')); } };