|
|
|
|
@ -109,4 +109,40 @@ class VerifyQccEnterprisePackInfoTest extends TestCase
|
|
|
|
|
['selected', ['--timeout' => 'abc']],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @dataProvider requestCases */
|
|
|
|
|
public function test_request_details_are_from_actual_call_even_on_failure(?string $failure): void
|
|
|
|
|
{
|
|
|
|
|
$this->company('unknown');
|
|
|
|
|
$before = DB::table('company_qcc_accounts')->get()->toJson();
|
|
|
|
|
$request = [
|
|
|
|
|
'method' => 'POST', 'url' => 'https://example.test/gateway/openapi/businessCollege/enterprise/packInfo',
|
|
|
|
|
'headers' => ['Content-Type' => 'application/json', 'customerId' => 'test-customer', 'timestamp' => '1234567890000', 'token' => 'test-signature'],
|
|
|
|
|
'json' => ['creditCode' => 'test-credit', 'enterpriseName' => '测试企业'],
|
|
|
|
|
];
|
|
|
|
|
$mock = Mockery::mock(YuanheRepository::class);
|
|
|
|
|
$mock->authKey = 'secret-not-for-output';
|
|
|
|
|
$mock->shouldReceive('enterprisePackInfo')->once()->with($request['json'], 120)
|
|
|
|
|
->andReturnUsing(function () use ($mock, $request, $failure) {
|
|
|
|
|
$mock->lastRequest = $request;
|
|
|
|
|
if ($failure !== null) {
|
|
|
|
|
throw new YuanhePackInfoException('请求超时', null, null, $failure === 'timeout' ? null : $failure);
|
|
|
|
|
}
|
|
|
|
|
return ['code' => 200];
|
|
|
|
|
});
|
|
|
|
|
$this->app->instance(YuanheRepository::class, $mock);
|
|
|
|
|
$exit = Artisan::call('qcc:verify-pack-info', ['company_id' => 333, '--timeout' => '120', '--raw' => true, '--request' => true]);
|
|
|
|
|
$this->assertSame($failure === null ? 0 : 1, $exit);
|
|
|
|
|
$expected = "请求信息(不含 authKey):\n".json_encode($request, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)."\n返回结果:\n";
|
|
|
|
|
$expected .= $failure === null ? json_encode(['code' => 200], JSON_PRETTY_PRINT) : ($failure === 'timeout' ? '请求超时' : $failure);
|
|
|
|
|
$this->assertSame($expected.PHP_EOL, Artisan::output());
|
|
|
|
|
$this->assertStringNotContainsString('secret-not-for-output', Artisan::output());
|
|
|
|
|
$this->assertSame($before, DB::table('company_qcc_accounts')->get()->toJson());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function requestCases(): array
|
|
|
|
|
{
|
|
|
|
|
return [[null], ['timeout'], ['<html>504 Gateway Time-out</html>']];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|