* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class ClientTest extends TestCase { public function testRequest() { $mock = new MockHandler([ new Response(200, ['X-Foo' => 'Bar'], 'foobar'), ]); $container = []; $history = Middleware::history($container); $stack = HandlerStack::create($mock); $stack->push($history); $client = new Client(['handler' => $stack]); $request = new GetRequest(new Url('http://localhost.com')); $response = $client->request($request); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Bar', (string) $response->getHeader('X-Foo')); $this->assertEquals('foobar', (string) $response->getBody()); $this->assertEquals(1, count($container)); $transaction = array_shift($container); $this->assertEquals('GET', $transaction['request']->getMethod()); $this->assertEquals(['localhost.com'], $transaction['request']->getHeader('Host')); } public function testRequestPost() { $mock = new MockHandler([ new Response(200, ['X-Foo' => 'Bar'], 'foobar'), ]); $container = []; $history = Middleware::history($container); $stack = HandlerStack::create($mock); $stack->push($history); $client = new Client(['handler' => $stack]); $request = new PostRequest(new Url('http://localhost.com'), [], 'foobar'); $response = $client->request($request); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Bar', (string) $response->getHeader('X-Foo')); $this->assertEquals('foobar', (string) $response->getBody()); $this->assertEquals(1, count($container)); $transaction = array_shift($container); $this->assertEquals('POST', $transaction['request']->getMethod()); $this->assertEquals(['localhost.com'], $transaction['request']->getHeader('Host')); $this->assertEquals('foobar', (string) $transaction['request']->getBody()); } public function testRequestSink() { $mock = new MockHandler([ new Response(200, ['X-Foo' => 'Bar'], 'foobar'), ]); $container = []; $history = Middleware::history($container); $stack = HandlerStack::create($mock); $stack->push($history); $file = __DIR__ . '/file.json'; $handle = fopen($file, 'w'); $options = new Options(); $options->setSink($handle); $client = new Client(['handler' => $stack]); $request = new PostRequest(new Url('http://localhost.com'), [], 'foobar'); $response = $client->request($request, $options); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Bar', (string) $response->getHeader('X-Foo')); $this->assertEquals('foobar', (string) $response->getBody()); $this->assertEquals('foobar', file_get_contents($file)); $this->assertEquals(1, count($container)); $transaction = array_shift($container); $this->assertEquals('POST', $transaction['request']->getMethod()); $this->assertEquals(['localhost.com'], $transaction['request']->getHeader('Host')); $this->assertEquals('foobar', (string) $transaction['request']->getBody()); } } __halt_compiler();----SIGNATURE:----mfMwIOxQlBvIAwFF4KBNxQ38VBs2nUY80C40o1UxmfPC+5PJWsT0CAEUkbB+qtu3L6HgPL1K0fGXnOh9PK4mMvJ2q/GhIMoQ3hr4otP1OUQdObZpmvRVUSlifSDiI8en+MfasRqC0zvkMMs0vyIpXVHUp29SppDfIlC0dpP7fq3TTDgdUeTwbPlg6uHXND5wZawZV8+n1M9wnkz1bHqOusjsl6uwEYWmD2LclsZADXRNCXe+UQEViBCLDuBIDHMNMhYXlj5ZAhNNfalITXZqfHvO726dOfkK1D9ZJ6e06cGv6xu+kziUBQjkkn5ryehqvi8p5YKolupohZbtV/OrnIeL4YMXWWcEvZ+F+bKU6cbLKpCWUl1jOjIuMv2xtD8KyKJ0vCsaOBD8y9dE6QLLKvgEjMbNNyzJZ/ePfiCQy95TDf9MpH5yoiDRtzxhV2wZAz90DFhxGQlJFiaM7KCI8WGtE41zrc70NmBOJRZd3kmSYLDyr+uLAEA/DZOPM2em7y6bywaIvxQ+zGa/ANlaTwUjXbW25rn5FkMiC8TjLfMW/3QzKo1MqPkk2ycn95V+/Gu3gMa2Qpy5HJOuqqiVpF4z+4VJPGBfNnbJNYv0hY2Z+HsRICXhrhuykCqqHQ8cQAsorv1kdb6Hx1Bt9Lo+ZPDgrEcel4NR/V6PIRDnQZ0=----ATTACHMENT:----OTk4NjA1MjU2MTU1NjAyMyA5MTY2MTQ4NzUwOTg4MjMyIDY0ODE1OTU3NTk2NjE3MDM=