mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-01 19:58:24 +08:00
增加单元测试
This commit is contained in:
parent
08d6a6326f
commit
794d4d3583
22
phpunit.xml
Normal file
22
phpunit.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -5,67 +5,68 @@ namespace Yansongda\Pay\Contracts;
|
||||
interface GatewayInterface
|
||||
{
|
||||
/**
|
||||
* 支付
|
||||
*
|
||||
* 支付.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
*
|
||||
* @version 2017-08-15
|
||||
*
|
||||
*
|
||||
* @param array $config_biz [description]
|
||||
*
|
||||
*
|
||||
* @return mixed [description]
|
||||
*/
|
||||
public function pay(array $config_biz);
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*
|
||||
* 退款.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
*
|
||||
* @version 2017-08-15
|
||||
*
|
||||
*
|
||||
* @param array|string $config_biz [description]
|
||||
*
|
||||
*
|
||||
* @return array|boolean [description]
|
||||
*/
|
||||
public function refund($config_biz);
|
||||
|
||||
/**
|
||||
* 关闭
|
||||
*
|
||||
* 关闭.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
*
|
||||
* @version 2017-08-15
|
||||
*
|
||||
*
|
||||
* @param array|string $config_biz [description]
|
||||
*
|
||||
*
|
||||
* @return array|boolean [description]
|
||||
*/
|
||||
public function close($config_biz);
|
||||
|
||||
/**
|
||||
* 对外接口 - 订单查询
|
||||
* 对外接口 - 订单查询.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
*
|
||||
* @version 2017-08-19
|
||||
*
|
||||
*
|
||||
* @param string $out_trade_no 商家订单号
|
||||
*
|
||||
*
|
||||
* @return array|boolean [description]
|
||||
*/
|
||||
public function find($out_trade_no);
|
||||
|
||||
/**
|
||||
* 验证消息是否官方发出
|
||||
*
|
||||
* 验证消息是否官方发出.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
*
|
||||
* @version 2017-08-15
|
||||
*
|
||||
*
|
||||
* @param mixed $data 待签名数组
|
||||
* @param string $sign 签名字符串-支付宝服务器发送过来的原始串
|
||||
* @param bool $sync 是否同步验证
|
||||
*
|
||||
*
|
||||
* @return array|boolean [description]
|
||||
*/
|
||||
public function verify($data, $sign = null, $sync = false);
|
||||
|
@ -100,7 +100,7 @@ class Pay
|
||||
*
|
||||
* @return object [description]
|
||||
*/
|
||||
private function createGateway($gateway)
|
||||
protected function createGateway($gateway)
|
||||
{
|
||||
if (!file_exists(__DIR__ . '/Gateways/' . ucfirst($this->drivers) . '/' . ucfirst($gateway) . 'Gateway.php')) {
|
||||
throw new InvalidArgumentException("Gateway [$gateway] is not supported.");
|
||||
@ -122,7 +122,7 @@ class Pay
|
||||
*
|
||||
* @return object [description]
|
||||
*/
|
||||
private function build($gateway)
|
||||
protected function build($gateway)
|
||||
{
|
||||
return new $gateway($this->config->get($this->drivers));
|
||||
}
|
||||
|
4
tests/Gateways/Alipay/AppGatewayTest.php
Normal file
4
tests/Gateways/Alipay/AppGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Alipay;
|
||||
|
4
tests/Gateways/Alipay/WapGatewayTest.php
Normal file
4
tests/Gateways/Alipay/WapGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Alipay;
|
||||
|
4
tests/Gateways/Alipay/WebGatewayTest.php
Normal file
4
tests/Gateways/Alipay/WebGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Alipay;
|
||||
|
4
tests/Gateways/Wechat/AppGatewayTest.php
Normal file
4
tests/Gateways/Wechat/AppGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Wechat;
|
||||
|
4
tests/Gateways/Wechat/MiniappGatewayTest.php
Normal file
4
tests/Gateways/Wechat/MiniappGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Wechat;
|
||||
|
4
tests/Gateways/Wechat/MpGatewayTest.php
Normal file
4
tests/Gateways/Wechat/MpGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Wechat;
|
||||
|
4
tests/Gateways/Wechat/PosGatewayTest.php
Normal file
4
tests/Gateways/Wechat/PosGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Wechat;
|
||||
|
0
tests/Gateways/Wechat/ScanGatewayTest.php
Normal file
0
tests/Gateways/Wechat/ScanGatewayTest.php
Normal file
4
tests/Gateways/Wechat/WapGatewayTest.php
Normal file
4
tests/Gateways/Wechat/WapGatewayTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Gateways\Wechat;
|
||||
|
@ -2,8 +2,50 @@
|
||||
|
||||
namespace Yansongda\Pay\Tests;
|
||||
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Contracts\GatewayInterface;
|
||||
use Yansongda\Pay\Exceptions\GatewayException;
|
||||
use Yansongda\Pay\Exceptions\InvalidArgumentException;
|
||||
|
||||
class PayTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testDriverWithoutConfig()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$pay = new Pay([]);
|
||||
$pay->driver('foo');
|
||||
}
|
||||
|
||||
public function testDriver()
|
||||
{
|
||||
$pay = new Pay(['alipay' => ['app_id' => '']]);
|
||||
|
||||
$this->assertInstanceOf(Pay::class, $pay->driver('alipay'));
|
||||
}
|
||||
|
||||
public function testGatewayWithoutDriver()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Driver is not defined.');
|
||||
|
||||
$pay = new Pay([]);
|
||||
$pay->gateway();
|
||||
}
|
||||
|
||||
public function testInvalidGateway()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Gateway [foo] is not supported.');
|
||||
|
||||
$pay = new Pay(['alipay' => ['app_id' => '']]);
|
||||
$pay->driver('alipay')->gateway('foo');
|
||||
}
|
||||
|
||||
public function testGateway()
|
||||
{
|
||||
$pay = new Pay(['alipay' => ['app_id' => '']]);
|
||||
$this->assertInstanceOf(GatewayInterface::class, $pay->driver('alipay')->gateway());
|
||||
}
|
||||
|
||||
}
|
||||
|
3
tests/Support/ConfigTest.php
Normal file
3
tests/Support/ConfigTest.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Support;
|
4
tests/Traits/HasHttpRequestTest.php
Normal file
4
tests/Traits/HasHttpRequestTest.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Traits;
|
||||
|
Loading…
Reference in New Issue
Block a user