接口 url 错误
修改理由:
相关信息:
- 类型:教程文章
- 文章: 编写单元测试
- 课程: 《LX2 PHP 扩展包实战教程 - 从入门到发布()》
此投稿状态为 标记为已读。
内容修改:
| Old | New | Differences |
|---|---|---|
| 80 | 80 | . |
| 81 | 81 | public function getWeather($city, $type = 'base', $format = 'json') |
| 82 | 82 | { |
| 83 | $url = 'https://restapi.amap.com/v3/weather/weatherInfo | |
| 83 | $url = 'https://restapi.amap.com/v3/weather/weatherInfo?parameters'; | |
| 84 | 84 | |
| 85 | 85 | // 1. 对 `$format` 与 `$type` 参数进行检查,不在范围内的抛出异常。 |
| 86 | 86 | if (!\in_array($format, ['xml', 'json'])) { | … | … |
| 236 | 236 | $client = \Mockery::mock(Client::class); |
| 237 | 237 | |
| 238 | 238 | // 指定将会产生的行为(在后续的测试中将会按下面的参数来调用)。 |
| 239 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo | |
| 239 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo?parameters', [ | |
| 240 | 240 | 'query' => [ |
| 241 | 241 | 'key' => 'mock-key', |
| 242 | 242 | 'city' => '深圳', | … | … |
| 283 | 283 | // json |
| 284 | 284 | $response = new Response(200, [], '{"success": true}'); |
| 285 | 285 | $client = \Mockery::mock(Client::class); |
| 286 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo | |
| 286 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo?parameters', [ | |
| 287 | 287 | 'query' => [ |
| 288 | 288 | 'key' => 'mock-key', |
| 289 | 289 | 'city' => '深圳', | … | … |
| 300 | 300 | // xml |
| 301 | 301 | $response = new Response(200, [], '<hello>content</hello>'); |
| 302 | 302 | $client = \Mockery::mock(Client::class); |
| 303 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo | |
| 303 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo?parameters', [ | |
| 304 | 304 | 'query' => [ |
| 305 | 305 | 'key' => 'mock-key', |
| 306 | 306 | 'city' => '深圳', | … | … |
| 463 | 463 | // json |
| 464 | 464 | $response = new Response(200, [], '{"success": true}'); |
| 465 | 465 | $client = \Mockery::mock(Client::class); |
| 466 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo | |
| 466 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo?parameters, [ | |
| 467 | 467 | 'query' => [ |
| 468 | 468 | 'key' => 'mock-key', |
| 469 | 469 | 'city' => '深圳', | … | … |
| 480 | 480 | // xml |
| 481 | 481 | $response = new Response(200, [], '<hello>content</hello>'); |
| 482 | 482 | $client = \Mockery::mock(Client::class); |
| 483 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo | |
| 483 | $client->allows()->get('https://restapi.amap.com/v3/weather/weatherInfo?parameters', [ | |
| 484 | 484 | 'query' => [ |
| 485 | 485 | 'key' => 'mock-key', |
| 486 | 486 | 'city' => '深圳', |
关于 LearnKu