代码内容不符
修改理由:
相关信息:
- 类型:教程文章
- 文章: 编写单元测试
- 课程: 《LX2 PHP 扩展包实战教程 - 从入门到发布()》
此投稿已在 7年前 合并。
内容修改:
| Old | New | Differences |
|---|---|---|
| 67 | 67 | |
| 68 | 68 | ```php |
| 69 | 69 | <?php |
| 70 | namespace Overtrue\Weather\Tests; | |
| 71 | ||
| 72 | use GuzzleHttp\Client; | |
| 73 | use GuzzleHttp\ClientInterface; | |
| 74 | use GuzzleHttp\Psr7\Response; | |
| 75 | use Mockery\Matcher\AnyArgs; | |
| 76 | use Overtrue\Weather\Exceptions\HttpException; | |
| 77 | use Overtrue\Weather\Exceptions\InvalidArgumentException; | |
| 78 | use Overtrue\Weather\Weather; | |
| 79 | use PHPUnit\Framework\TestCase; | |
| 80 | ||
| 81 | class WeatherTest extends TestCase | |
| 70 | namespace Overtrue\Weather; | |
| 71 | ||
| 72 | use GuzzleHttp\Client; | |
| 73 | use Overtrue\Weather\Exceptions\HttpException; | |
| 74 | use Overtrue\Weather\Exceptions\InvalidArgumentException; | |
| 75 | ||
| 76 | class Weather | |
| 82 | 77 | { |
| 83 | 78 | . |
| 84 | 79 | . |
| 85 | 80 | . |
| 86 | public function getWeather($city, | |
| 81 | public function getWeather($city, string $type = 'base', string $format = 'json') | |
| 87 | 82 | { |
| 88 | 83 | $url = 'https://restapi.amap.com/v3/weather/weatherInfo'; |
| 89 | 84 | |
| 90 | 85 | // 1. 对 `$format` 与 `$extensions` 参数进行检查,不在范围内的抛出异常。 |
| 91 | if (!\in_array( | |
| 86 | if (!\in_array(\strtolower($format), ['xml', 'json'])) { | |
| 92 | 87 | throw new InvalidArgumentException('Invalid response format: '. $format); |
| 93 | 88 | } |
| 94 | 89 | |
| 95 | 90 | if (!\in_array(\strtolower($type), ['base', 'all'])) { |
| 96 | throw new InvalidArgumentException('Invalid type value(base/all): '. | |
| 91 | throw new InvalidArgumentException('Invalid type value(base/all): '. $type); | |
| 97 | 92 | } |
| 98 | 93 | |
| 99 | 94 | // 2. 封装 query 参数,并对空值进行过滤。 |
关于 LearnKu