test: add Wechat/Pay/Common/QueryPluginTest.php

This commit is contained in:
conlin-local-docker 2021-08-31 22:38:01 +08:00 committed by yansongda
parent 76c2b7b020
commit 83cdb21ba0

View File

@ -0,0 +1,96 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Pay\Common;
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Message\RequestInterface;
use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
use Yansongda\Pay\Exception\InvalidParamsException;
class QueryPluginTest extends TestCase
{
public function testNormalTransactionId()
{
$rocket = new Rocket();
$config = get_wechat_config($rocket->getParams([]));
$rocket->setPayload(new Collection(['transaction_id'=>'121212']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals('1600314069', $config->get('mch_id'));
self::assertEquals('/v3/pay/transactions/id/121212', $radar->getUri()->getPath());
self::assertEquals('mchid=1600314069', $radar->getUri()->getQuery());
self::assertEquals('GET', $radar->getMethod());
self::assertStringNotContainsString('sp_mchid', $radar->getUri()->getQuery());
}
public function testNormalOutTradeNo()
{
$rocket = new Rocket();
$rocket->setPayload(new Collection(['out_trade_no'=>'121212']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals('/v3/pay/transactions/out-trade-no/121212', $radar->getUri()->getPath());
self::assertEquals('mchid=1600314069', $radar->getUri()->getQuery());
self::assertEquals('GET', $radar->getMethod());
self::assertStringNotContainsString('sp_mchid', $radar->getUri()->getQuery());
}
public function testPartnerTransactionId()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider']);
$rocket->setPayload(new Collection(['transaction_id'=>'121212','sub_mchid' => '1600314077']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals('/v3/pay/partner/transactions/id/121212', $radar->getUri()->getPath());
self::assertEquals('GET', $radar->getMethod());
self::assertStringContainsString('sub_mchid=1600314077', $radar->getUri()->getQuery());
self::assertStringContainsString('sp_mchid=1600314069', $radar->getUri()->getQuery());
}
public function testPartnerOutTradeNo()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider']);
$rocket->setPayload(new Collection(['out_trade_no'=>'121218','sub_mchid' => '1600314099']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals('/v3/pay/partner/transactions/out-trade-no/121218', $radar->getUri()->getPath());
self::assertEquals('GET', $radar->getMethod());
self::assertStringContainsString('sub_mchid=1600314099', $radar->getUri()->getQuery());
self::assertStringContainsString('sp_mchid=1600314069', $radar->getUri()->getQuery());
}
// public function testPartner()
// {
// $rocket = new Rocket();
// $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '1600314071']));
//
// $plugin = new RefundPlugin();
//
// $result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
// $payload = $result->getPayload();
//
// self::assertEquals('1600314071', $payload->get('sub_mchid'));
// }
}