|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use GuzzleHttp\Client; |
3 | 4 | use GuzzleHttp\Cookie\CookieJar; |
4 | 5 | use Symfony\Component\Process\Process; |
5 | | -use GuzzleHttp\Client; |
6 | 6 |
|
7 | 7 | $process = null; |
8 | 8 | beforeAll(function () use (&$process) { |
9 | | - $process = new Process(['php', 'think', 'worker'], __DIR__ . '/stub/'); |
| 9 | + $process = new Process(['php', 'think', 'worker'], STUB_DIR); |
10 | 10 | $process->start(); |
11 | 11 | $wait = 0; |
12 | 12 |
|
|
25 | 25 | }); |
26 | 26 |
|
27 | 27 | beforeEach(function () { |
28 | | - $this->client = new Client([ |
| 28 | + $this->httpClient = new Client([ |
29 | 29 | 'base_uri' => 'http://127.0.0.1:8080', |
30 | 30 | 'cookies' => true, |
31 | 31 | 'http_errors' => false, |
| 32 | + 'timeout' => 1, |
32 | 33 | ]); |
33 | 34 | }); |
34 | 35 |
|
35 | 36 | it('callback route', function () { |
36 | | - $response = $this->client->get('/'); |
| 37 | + $response = $this->httpClient->get('/'); |
37 | 38 |
|
38 | 39 | expect($response->getStatusCode()) |
39 | 40 | ->toBe(200) |
|
44 | 45 | it('controller route', function () { |
45 | 46 | $jar = new CookieJar(); |
46 | 47 |
|
47 | | - $response = $this->client->get('/test', ['cookies' => $jar]); |
| 48 | + $response = $this->httpClient->get('/test', ['cookies' => $jar]); |
48 | 49 |
|
49 | 50 | expect($response->getStatusCode()) |
50 | 51 | ->toBe(200) |
|
59 | 60 | $data = [ |
60 | 61 | 'name' => 'think', |
61 | 62 | ]; |
62 | | - $response = $this->client->post('/json', [ |
| 63 | + $response = $this->httpClient->post('/json', [ |
63 | 64 | 'json' => $data, |
64 | 65 | ]); |
65 | 66 |
|
|
70 | 71 | }); |
71 | 72 |
|
72 | 73 | it('put and delete request', function () { |
73 | | - $response = $this->client->put('/'); |
| 74 | + $response = $this->httpClient->put('/'); |
74 | 75 |
|
75 | 76 | expect($response->getStatusCode()) |
76 | 77 | ->toBe(200) |
77 | 78 | ->and($response->getBody()->getContents()) |
78 | 79 | ->toBe('put'); |
79 | 80 |
|
80 | | - $response = $this->client->delete('/'); |
| 81 | + $response = $this->httpClient->delete('/'); |
81 | 82 |
|
82 | 83 | expect($response->getStatusCode()) |
83 | 84 | ->toBe(200) |
|
86 | 87 | }); |
87 | 88 |
|
88 | 89 | it('file response', function () { |
89 | | - $response = $this->client->get('/static/asset.txt'); |
| 90 | + $response = $this->httpClient->get('/static/asset.txt'); |
90 | 91 |
|
91 | 92 | expect($response->getStatusCode()) |
92 | 93 | ->toBe(200) |
93 | 94 | ->and($response->getBody()->getContents()) |
94 | | - ->toBe(file_get_contents(__DIR__ . '/stub/public/asset.txt')); |
| 95 | + ->toBe(file_get_contents(STUB_DIR . '/public/asset.txt')); |
95 | 96 | }); |
96 | 97 |
|
97 | 98 | it('hot update', function () { |
98 | | - $response = $this->client->get('/hot'); |
| 99 | + $response = $this->httpClient->get('/hot'); |
99 | 100 |
|
100 | 101 | expect($response->getStatusCode()) |
101 | 102 | ->toBe(404); |
|
110 | 111 | }); |
111 | 112 | PHP; |
112 | 113 |
|
113 | | - file_put_contents(__DIR__ . '/stub/route/hot.php', $route); |
| 114 | + file_put_contents(STUB_DIR . '/route/hot.php', $route); |
114 | 115 |
|
115 | 116 | sleep(2); |
116 | 117 |
|
117 | | - $response = $this->client->get('/hot'); |
| 118 | + $response = $this->httpClient->get('/hot'); |
118 | 119 |
|
119 | 120 | expect($response->getStatusCode()) |
120 | 121 | ->toBe(200) |
121 | 122 | ->and($response->getBody()->getContents()) |
122 | 123 | ->toBe('hot'); |
123 | 124 | })->after(function () { |
124 | | - @unlink(__DIR__ . '/stub/route/hot.php'); |
| 125 | + @unlink(STUB_DIR . '/route/hot.php'); |
125 | 126 | })->skipOnWindows(); |
0 commit comments