Skip to content

Commit ae41e9f

Browse files
committed
完善
1 parent 51a405a commit ae41e9f

File tree

1 file changed

+25
-45
lines changed

1 file changed

+25
-45
lines changed

tests/HttpTest.php

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
beforeAll(function () use (&$process) {
99
$process = new Process(['php', 'think', 'worker'], __DIR__ . '/stub/');
1010
$process->start();
11+
$wait = 0;
12+
1113
while (!$process->getOutput()) {
14+
$wait++;
15+
if ($wait > 10) {
16+
throw new Exception('server start failed');
17+
}
1218
sleep(1);
1319
}
1420
});
@@ -18,30 +24,27 @@
1824
$process->stop();
1925
});
2026

21-
test('tests callback route', function () {
22-
$client = new Client([
27+
beforeEach(function () {
28+
$this->client = new Client([
2329
'base_uri' => 'http://127.0.0.1:8080',
2430
'cookies' => true,
2531
'http_errors' => false,
2632
]);
33+
});
2734

28-
$response = $client->get('/');
35+
it('callback route', function () {
36+
$response = $this->client->get('/');
2937

3038
expect($response->getStatusCode())
3139
->toBe(200)
3240
->and($response->getBody()->getContents())
3341
->toBe('hello world');
3442
});
3543

36-
test('tests controller route', function () {
37-
$jar = new CookieJar();
38-
$client = new Client([
39-
'base_uri' => 'http://127.0.0.1:8080',
40-
'cookies' => $jar,
41-
'http_errors' => false,
42-
]);
44+
it('controller route', function () {
45+
$jar = new CookieJar();
4346

44-
$response = $client->get('/test');
47+
$response = $this->client->get('/test', ['cookies' => $jar]);
4548

4649
expect($response->getStatusCode())
4750
->toBe(200)
@@ -51,16 +54,12 @@
5154
->toBe('think');
5255
});
5356

54-
test('tests json post', function () {
55-
$client = new Client([
56-
'base_uri' => 'http://127.0.0.1:8080',
57-
'cookies' => true,
58-
'http_errors' => false,
59-
]);
57+
it('json post', function () {
58+
6059
$data = [
6160
'name' => 'think',
6261
];
63-
$response = $client->post('/json', [
62+
$response = $this->client->post('/json', [
6463
'json' => $data,
6564
]);
6665

@@ -70,52 +69,33 @@
7069
->toBe(json_encode($data));
7170
});
7271

73-
test('tests put and delete request', function () {
74-
$client = new Client([
75-
'base_uri' => 'http://127.0.0.1:8080',
76-
'cookies' => true,
77-
'http_errors' => false,
78-
]);
79-
80-
$response = $client->put('/');
72+
it('put and delete request', function () {
73+
$response = $this->client->put('/');
8174

8275
expect($response->getStatusCode())
8376
->toBe(200)
8477
->and($response->getBody()->getContents())
8578
->toBe('put');
8679

87-
$response = $client->delete('/');
80+
$response = $this->client->delete('/');
8881

8982
expect($response->getStatusCode())
9083
->toBe(200)
9184
->and($response->getBody()->getContents())
9285
->toBe('delete');
9386
});
9487

95-
test('tests file response', function () {
96-
$client = new Client([
97-
'base_uri' => 'http://127.0.0.1:8080',
98-
'cookies' => true,
99-
'http_errors' => false,
100-
]);
101-
102-
$response = $client->get('/static/asset.txt');
88+
it('file response', function () {
89+
$response = $this->client->get('/static/asset.txt');
10390

10491
expect($response->getStatusCode())
10592
->toBe(200)
10693
->and($response->getBody()->getContents())
10794
->toBe(file_get_contents(__DIR__ . '/stub/public/asset.txt'));
10895
});
10996

110-
test('tests hot update', function () {
111-
112-
$client = new Client([
113-
'base_uri' => 'http://127.0.0.1:8080',
114-
'cookies' => true,
115-
'http_errors' => false,
116-
]);
117-
118-
$response = $client->get('/hot');
97+
it('hot update', function () {
98+
$response = $this->client->get('/hot');
11999

120100
expect($response->getStatusCode())
121101
->toBe(404);
@@ -134,7 +114,7 @@
134114

135115
sleep(2);
136116

137-
$response = $client->get('/hot');
117+
$response = $this->client->get('/hot');
138118

139119
expect($response->getStatusCode())
140120
->toBe(200)

0 commit comments

Comments
 (0)