/** * Get all of the received requests * * @param bool $hydrate Set to TRUE to turn the messages into * actual {@see RequestInterface} objects. If $hydrate is FALSE, * requests will be returned as strings. * * @return array * @throws \RuntimeException */ public static function received($hydrate = false) { $response = TestServer::received(); if ($hydrate) { $c = new Client(); $factory = new MessageFactory(); $response = array_map(function ($message) use($factory, $c) { return RingBridge::fromRingRequest($message); }, $response); } return $response; }
public function testCanCancel() { Server::flush(); $response = ['status' => 200]; Server::enqueue(array_fill_keys(range(0, 10), $response)); $a = new CurlMultiHandler(); $responses = []; for ($i = 0; $i < 10; $i++) { $response = $a(['http_method' => 'GET', 'headers' => ['host' => [Server::$host]], 'future' => 'lazy']); $response->cancel(); $responses[] = $response; } $this->assertCount(0, Server::received()); foreach ($responses as $response) { $this->assertTrue($this->readAttribute($response, 'isRealized')); } }
public function testDoesNotAddContentTypeByDefault() { $this->queueRes(); $handler = new StreamHandler(); $handler(['http_method' => 'PUT', 'uri' => '/', 'headers' => ['host' => [Server::$host], 'content-length' => [3]], 'body' => 'foo']); $req = Server::received()[0]; $this->assertEquals('', Core::header($req, 'Content-Type')); $this->assertEquals(3, Core::header($req, 'Content-Length')); }
public function testSendsPostWithNoBodyOrDefaultContentType() { Server::flush(); Server::enqueue([['status' => 200]]); $handler = new CurlMultiHandler(); $response = $handler(['http_method' => 'POST', 'uri' => '/', 'headers' => ['host' => [Server::$host]]]); $response->wait(); $received = Server::received()[0]; $this->assertEquals('POST', $received['http_method']); $this->assertNull(Core::header($received, 'content-type')); $this->assertSame('0', Core::firstHeader($received, 'content-length')); }