1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GuillermoandraeTest\Highrise\Http; |
4
|
|
|
|
5
|
|
|
use Guillermoandrae\Highrise\Http\GuzzleAdapter; |
6
|
|
|
use Guillermoandrae\Highrise\Http\RequestException; |
7
|
|
|
use GuillermoandraeTest\Highrise\TestCase; |
8
|
|
|
use GuzzleHttp\Client; |
9
|
|
|
|
10
|
|
|
class GuzzleAdapterTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testRequestWithBody() |
13
|
|
|
{ |
14
|
|
|
$body = '<test><name>test</name></test>'; |
15
|
|
|
$client = $this->getMockClient(201); |
16
|
|
|
$adapter = $this->getAdapter($client); |
17
|
|
|
$adapter->request('GET', '/test.xml', ['body' => $body]); |
18
|
|
|
$this->assertSame($body, (string) $adapter->getLastRequest()->getBody()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testRequestWithoutBody() |
22
|
|
|
{ |
23
|
|
|
$client = $this->getMockClient(200); |
24
|
|
|
$adapter = $this->getAdapter($client); |
25
|
|
|
$adapter->request('DELETE', '/test.xml'); |
26
|
|
|
$this->assertEmpty((string) $adapter->getLastRequest()->getBody()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testRequestWithHeadersWithoutBody() |
30
|
|
|
{ |
31
|
|
|
$client = $this->getMockClient(200); |
32
|
|
|
$adapter = $this->getAdapter($client); |
33
|
|
|
$adapter->request('GET', '/test.xml', ['headers' => ['X-Test' => 'test']]); |
34
|
|
|
$this->assertArrayHasKey('X-Test', $adapter->getLastRequest()->getHeaders()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testInvalidRequestWithoutBody() |
38
|
|
|
{ |
39
|
|
|
$this->expectException(RequestException::class); |
40
|
|
|
$client = $this->getMockClient(503); |
41
|
|
|
$adapter = $this->getAdapter($client); |
42
|
|
|
$adapter->request('DELETE', '/test.xml'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testGetClient() |
46
|
|
|
{ |
47
|
|
|
$this->assertInstanceOf(Client::class, (new GuzzleAdapter('a', 'b'))->getClient()); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|