* @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:----OOl/+LEyg8FVac2heWBC+9Xl6+z5BbJEN53bT0BMAtqs6dZWStdm7B2OMo7JgbKdfFeD1VBGWD0UUfPyTEI2O0b+rq4nkfmPHcdmjh5y15Z032nWaoXqOV4hRjGO0sAYVySQpR5tWw5GF8WiW+IpEy6UdXVGg9h5ZGFAaO/I+nVOf+hwY+2miOdt54BkRdOm2PDn++mPmzy8wtYd/dSKjJ5QEDqwzVOSTlibZs0GQ3e/YoKqVqyiF+47yG8huVXkrNFne3VMPG34jkKgsvonMXBP0Qfs2pzWG1qyKUTz1EQ8hDEjvAyeEH2K9K3Ejsnlsfe6DCgONoPzMygSZk5SX3yAdwOtDuswIkpaSfZ7t5i/kMPjae1nv1EL0+dLoI8jgGYDieEUc7aE+EfV9Z0ZXI71vis8pK7bnYR31s45jyhaiGRg/al60rjpJy8OLMvK+WCCAtfn0hWj6mdNzcBw3LpjDttua6s77ULEG5fKDrt2/zKUijFZbkJL1HuYebDMmYm7ywVPQd0UjEZbgOUqQ2EWTdE+CauFMq2zluOyfbISNN7dZpZBvnge7k9oFrATO1gkC9nahWSCZ+eaml8aeK0oI12K927ygKhnyai5JfptYxicT1zPukIcXU59nL23ZfiFFZXSXH6hYHuaZm6m8mNUpmD9EfR4xLPfQFPH4MA=----ATTACHMENT:----Nzc5NzcxNDU3NDc1NzMwMCA4MTU0MjExNDc4ODkwMzc0IDI1NDc4MzY0NjE0NDM5MTA=