expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid type value(base/all): foo'); $w->getProductOrder('SN23454324565432'); $this->fail('Failed to assert getOrder throw exception with invalid argument.'); } public function testGetWeatherWithInvalidFormat() { $w = new Order('mock-key', 'base', 'array'); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid response format: array'); $w->getProductOrder('SN23454324565432'); $this->fail('Failed to assert getOrder throw exception with invalid argument.'); } public function testGetWeatherWithGuzzleRuntimeException() { $client = \Mockery::mock(Client::class); $client->allows() ->get(new AnyArgs()) ->andThrow(new \Exception('request timeout')); $w = \Mockery::mock(Order::class, ['mock-key'])->makePartial(); $w->allows()->getHttpClient()->andReturn($client); $this->expectException(HttpException::class); //$this->expectExceptionMessage('request timeout'); $w->getProductOrder('SN23454324565432'); } public function testGetHttpClient() { $w = new Order('mock-key'); // 断言返回结果为 GuzzleHttp\ClientInterface 实例 $this->assertInstanceOf(ClientInterface::class, $w->getHttpClient()); } public function testSetGuzzleOptions() { $w = new Order('mock-key'); // 设置参数前,timeout 为 null $this->assertNull($w->getHttpClient()->getConfig('timeout')); // 设置参数 $w->setGuzzleOptions(['timeout' => 5000]); // 设置参数后,timeout 为 5000 $this->assertSame(5000, $w->getHttpClient()->getConfig('timeout')); } public function testGetProductOrder() { $w = new Order('mock-key'); $w->getProductOrder('SN23454324565432'); $this->assertInstanceOf(ClientInterface::class, $w->getHttpClient()); } }