forked from intercom/intercom-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntercomTestCase.php
More file actions
95 lines (75 loc) · 2.06 KB
/
Copy pathIntercomTestCase.php
File metadata and controls
95 lines (75 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Intercom;
use Guzzle\Tests\GuzzleTestCase;
class IntercomTestCase extends GuzzleTestCase
{
protected $client;
public function setUp()
{
$this->client = IntercomBasicAuthClient::factory([
'api_key' => '1234',
'app_id' => 'my-app'
]);
}
protected function getOnlyMockedRequest($method = null, $path = null)
{
$requests = $this->getMockedRequests();
$count = count($requests);
if ($count != 1)
{
$this->fail("Expected 1 HTTP request, got $count!");
}
$request = $requests[0];
if ($method && $path)
{
$this->assertRequest($method, $path, $request);
}
else if ($method || $path)
{
$this->fail('$method and $path must both be present or null.');
}
return $request;
}
protected function assertRequest($method, $path, $request = null)
{
if (!$request)
{
$request = $this->getOnlyMockedRequest();
}
$this->assertEquals($method, $request->getMethod());
$this->assertEquals($path, $request->getResource());
}
protected function assertBasicAuth($username, $password, $request = null)
{
if (!$request)
{
$request = $this->getOnlyMockedRequest();
}
$header = $request->getHeader('Authorization');
if (!$header)
{
$this->fail("Missing Authorization header.");
}
$this->assertEquals(
'Basic ' . base64_encode("$username:$password"),
$header->__toString()
);
}
protected function assertRequestJson($object, $request = null)
{
if (!$request)
{
$request = $this->getOnlyMockedRequest();
}
$body = $request->getBody();
if (!$body)
{
$this->fail('Missing request entity body.');
}
$this->assertEquals(
json_encode($object),
$body->__toString()
);
}
}
?>