1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GuillermoandraeTest\Highrise; |
4
|
|
|
|
5
|
|
|
use Guillermoandrae\Highrise\Http\GuzzleAdapter; |
6
|
|
|
use Guillermoandrae\Highrise\Resources\ResourceFactory; |
7
|
|
|
use Guillermoandrae\Highrise\Resources\ResourceInterface; |
8
|
|
|
use GuzzleHttp\Client; |
9
|
|
|
use GuzzleHttp\Handler\MockHandler; |
10
|
|
|
use GuzzleHttp\HandlerStack; |
11
|
|
|
use GuzzleHttp\Psr7\Response; |
12
|
|
|
use PHPUnit\Framework\TestCase as PHPUnitTestCase; |
13
|
|
|
|
14
|
|
|
class TestCase extends PHPUnitTestCase |
15
|
|
|
{ |
16
|
|
|
protected function assertSameLastRequestUri(string $uri, ResourceInterface $resource) |
17
|
|
|
{ |
18
|
|
|
$this->assertSame($uri, $resource->getAdapter()->getLastRequest()->getUri()->getPath()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected function getMockResource(string $name, string $expectedBody) |
22
|
|
|
{ |
23
|
|
|
$client = $this->getMockClient(200, [], $expectedBody); |
24
|
|
|
$adapter = $this->getAdapter($client); |
25
|
|
|
return ResourceFactory::factory($name, $adapter); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function getAdapter(Client $client): GuzzleAdapter |
29
|
|
|
{ |
30
|
|
|
$adapter = new GuzzleAdapter('test', '123456'); |
31
|
|
|
$adapter->setClient($client); |
32
|
|
|
return $adapter; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function getMockClient($expectedHttpStatusCode, array $expectedHeaders = [], $expectedBody = ''): Client |
36
|
|
|
{ |
37
|
|
|
$mock = new MockHandler([ |
38
|
|
|
new Response($expectedHttpStatusCode, $expectedHeaders, $expectedBody) |
39
|
|
|
]); |
40
|
|
|
$handler = HandlerStack::create($mock); |
41
|
|
|
return new Client(['handler' => $handler]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function getAccountXml(): string |
45
|
|
|
{ |
46
|
|
|
return '<account> |
47
|
|
|
<id type="integer">1</id> |
48
|
|
|
<name>Your Company</name> |
49
|
|
|
<subdomain>yourco</subdomain> |
50
|
|
|
<plan>premium</plan> |
51
|
|
|
<owner-id type="integer"></owner-id> |
52
|
|
|
<people-count type="integer">9412</people-count> |
53
|
|
|
<storage type="integer">17374444</storage> |
54
|
|
|
<color_theme>blue</color_theme> |
55
|
|
|
<ssl_enabled>true</ssl_enabled> |
56
|
|
|
<created-at type="datetime">2007-01-12T15:00:00Z</created-at> |
57
|
|
|
<updated-at type="datetime">2007-01-12T15:00:00Z</updated-at> |
58
|
|
|
</account>'; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|