forked from catchpoint/WebPageTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPSignupClientTest.php
149 lines (140 loc) · 4.46 KB
/
CPSignupClientTest.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use WebPageTest\CPSignupClient;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Middleware;
final class CPSignupClientTest extends TestCase
{
public function testGetWptPlans(): void
{
$auth_handler = $this->createMockResponse(200, '{
"access_token": "123456",
"scope": "fooby",
"expires_in": "sure"
}');
$handler = $this->createMockResponse(200, '{
"data": {
"wptPlan": [
{
"name": "MP1",
"priceInCents": 1874,
"description": "MP1",
"interval": 1,
"monthlyTestRuns": 1200
},
{
"name": "MP2",
"priceInCents": 500,
"description": "MP2",
"interval": 1,
"monthlyTestRuns": 5000
},
{
"name": "MP3",
"priceInCents": 12499,
"description": "MP3",
"interval": 1,
"monthlyTestRuns": 12000
},
{
"name": "AP1",
"priceInCents": 17988,
"description": "AP1",
"interval": 12,
"monthlyTestRuns": 1200
},
{
"name": "MP4",
"priceInCents": 24999,
"description": "MP4",
"interval": 1,
"monthlyTestRuns": 25000
},
{
"name": "AP2",
"priceInCents": 59988,
"description": "AP2",
"interval": 12,
"monthlyTestRuns": 5000
},
{
"name": "AP3",
"priceInCents": 119988,
"description": "AP3",
"interval": 12,
"monthlyTestRuns": 12000
},
{
"name": "AP4",
"priceInCents": 158388,
"description": "",
"interval": 12,
"monthlyTestRuns": 25000
},
{
"name": "AP5",
"priceInCents": 158388,
"description": "",
"interval": 12,
"monthlyTestRuns": 25000
},
{
"name": "AP6",
"priceInCents": 158388,
"description": "",
"interval": 12,
"monthlyTestRuns": 25000
},
{
"name": "MP7",
"priceInCents": 158388,
"description": "",
"interval": 12,
"monthlyTestRuns": 25000
}
]
}
}');
//$host = "http://webpagetest.org";
$client = new CPSignupClient([
'base_uri' => '127.0.0.2',
'redirect_base_uri' => '127.0.0.3',
'gql_uri' => '127.0.0.4',
'client_id' => '123',
'client_secret' => '345',
'grant_type' => 'these are good to have',
'auth_handler' => $auth_handler,
'handler' => $handler
]);
$plans = $client->getWptPlans();
$this->assertEquals(3, count($plans));
}
private function createMockResponse(int $status, string $body): HandlerStack
{
$mock = new MockHandler([new Response($status, [], $body)]);
return HandlerStack::create($mock);
}
/*
* @param array { status: int, body: string } $resps
*
*/
private function createMockResponses(array $resps): HandlerStack
{
//@var array { Response } $responses
$responses = array_map(function ($resp) {
return new Response($resp['status'], [], $resp['body']);
}, $resps);
$mock = new MockHandler($responses);
return HandlerStack::create($mock);
}
private function createRequestMock(array &$results): HandlerStack
{
$history = Middleware::history($results);
$handler = HandlerStack::create();
$handler->push($history);
return $handler;
}
}