Skip to content

Commit

Permalink
test: 修复单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaojie committed Jun 22, 2024
1 parent 289f197 commit 100f8dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Plugin/Jsb/ResponsePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ protected function validateResponse(Rocket $rocket): void
&& ($destinationOrigin->getStatusCode() < 200 || $destinationOrigin->getStatusCode() >= 300)) {
throw new InvalidResponseException(Exception::RESPONSE_CODE_WRONG, '江苏银行返回状态码异常,请检查参数是否错误', $rocket->getDestination());
}

if ($destination instanceof Collection && '000000' !== $destination->get('respCode')) {
throw new InvalidResponseException(Exception::RESPONSE_BUSINESS_CODE_WRONG, sprintf('江苏银行返回错误: respCode:%s respMsg:%s', $destination->get('respCode'), $destination->get('respMsg')), $rocket->getDestination());
}
Expand Down
12 changes: 9 additions & 3 deletions tests/Plugin/Jsb/ResponsePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use GuzzleHttp\Psr7\Response;
use Yansongda\Artful\Exception\InvalidResponseException;
use Yansongda\Artful\Plugin\ParserPlugin;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Plugin\Jsb\ResponsePlugin;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Arr;
use Yansongda\Supports\Collection;

class ResponsePluginTest extends TestCase
{
Expand All @@ -24,7 +27,8 @@ public function testNormal()
{
$body = 'errCode=&field1=&field2=&field3=&orderNo=20240617144526400259379&orderStatus=1&outTradeNo=YC202406170003&partnerId=6a13eab71c4f4b0aa4757eda6fc59710&payUrl=http://weixintest.jsbchina.cn/epcs/qr/login.htm?qrCode=2018060611052793473720240617144526688568&respBizDate=20240617&respCode=000000&respMsg=交易成功&totalFee=0.01&validTime=2&signType=RSA&sign=jN3Ha6J9UUIe9M0L/XeexEdaRL9GB6nMV12wNC7LQvTS6V4nKHj4Qzw6M8cNsA9L0Tb3QFT83B0qO3FJnruDrcHKqBLZb4FkoKKN/WiDBuA2UZQjG4+CBejoGJWfpkWSsei9tXUk36TB27lc2ZlYXSEwuuDwM7M9yvlYysc3fjg=';

$rocket = (new Rocket())->setDestinationOrigin(new Response(200, [], $body));
$rocket = (new Rocket())->setDestinationOrigin(new Response(200, [], $body))
->setDestination(new Collection(Arr::wrapQuery($body)));
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertSame($rocket, $result);
}
Expand All @@ -35,7 +39,8 @@ public function testCodeWrong()
self::expectExceptionCode(Exception::RESPONSE_BUSINESS_CODE_WRONG);
$body = 'errCode=1&field1=&field2=&field3=&orderNo=20240617144526400259379&orderStatus=1&outTradeNo=YC202406170003&partnerId=6a13eab71c4f4b0aa4757eda6fc59710&payUrl=http://weixintest.jsbchina.cn/epcs/qr/login.htm?qrCode=2018060611052793473720240617144526688568&respBizDate=20240617&respCode=000001&respMsg=交易成功&totalFee=0.01&validTime=2&signType=RSA&sign=jN3Ha6J9UUIe9M0L/XeexEdaRL9GB6nMV12wNC7LQvTS6V4nKHj4Qzw6M8cNsA9L0Tb3QFT83B0qO3FJnruDrcHKqBLZb4FkoKKN/WiDBuA2UZQjG4+CBejoGJWfpkWSsei9tXUk36TB27lc2ZlYXSEwuuDwM7M9yvlYysc3fjg=';

$rocket = (new Rocket())->setDestinationOrigin(new Response(200, [], $body));
$rocket = (new Rocket())->setDestinationOrigin(new Response(200, [], $body))
->setDestination(new Collection(Arr::wrapQuery($body)));

$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertSame($rocket, $result);
Expand All @@ -48,7 +53,8 @@ public function testHttpWrong()
self::expectExceptionMessage('江苏银行返回状态码异常,请检查参数是否错误');
$body = 'errCode=1&field1=&field2=&field3=&orderNo=20240617144526400259379&orderStatus=1&outTradeNo=YC202406170003&partnerId=6a13eab71c4f4b0aa4757eda6fc59710&payUrl=http://weixintest.jsbchina.cn/epcs/qr/login.htm?qrCode=2018060611052793473720240617144526688568&respBizDate=20240617&respCode=000000&respMsg=交易成功&totalFee=0.01&validTime=2&signType=RSA&sign=jN3Ha6J9UUIe9M0L/XeexEdaRL9GB6nMV12wNC7LQvTS6V4nKHj4Qzw6M8cNsA9L0Tb3QFT83B0qO3FJnruDrcHKqBLZb4FkoKKN/WiDBuA2UZQjG4+CBejoGJWfpkWSsei9tXUk36TB27lc2ZlYXSEwuuDwM7M9yvlYysc3fjg=';

$rocket = (new Rocket())->setDestinationOrigin(new Response(500, [], $body));
$rocket = (new Rocket())->setDestinationOrigin(new Response(500, [], $body))
->setDestination(new Collection(Arr::wrapQuery($body)));

$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertSame($rocket, $result);
Expand Down

0 comments on commit 100f8dd

Please sign in to comment.