增加单元测试

This commit is contained in:
yansongda 2017-08-21 21:54:26 +08:00
parent 08d6a6326f
commit 794d4d3583
15 changed files with 132 additions and 28 deletions

22
phpunit.xml Normal file
View 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>

View File

@ -5,7 +5,7 @@ namespace Yansongda\Pay\Contracts;
interface GatewayInterface interface GatewayInterface
{ {
/** /**
* 支付 * 支付.
* *
* @author yansongda <me@yansongda.cn> * @author yansongda <me@yansongda.cn>
* *
@ -18,7 +18,7 @@ interface GatewayInterface
public function pay(array $config_biz); public function pay(array $config_biz);
/** /**
* 退款 * 退款.
* *
* @author yansongda <me@yansongda.cn> * @author yansongda <me@yansongda.cn>
* *
@ -31,7 +31,7 @@ interface GatewayInterface
public function refund($config_biz); public function refund($config_biz);
/** /**
* 关闭 * 关闭.
* *
* @author yansongda <me@yansongda.cn> * @author yansongda <me@yansongda.cn>
* *
@ -44,7 +44,8 @@ interface GatewayInterface
public function close($config_biz); public function close($config_biz);
/** /**
* 对外接口 - 订单查询 * 对外接口 - 订单查询.
*
* @author yansongda <me@yansongda.cn> * @author yansongda <me@yansongda.cn>
* *
* @version 2017-08-19 * @version 2017-08-19
@ -56,7 +57,7 @@ interface GatewayInterface
public function find($out_trade_no); public function find($out_trade_no);
/** /**
* 验证消息是否官方发出 * 验证消息是否官方发出.
* *
* @author yansongda <me@yansongda.cn> * @author yansongda <me@yansongda.cn>
* *

View File

@ -100,7 +100,7 @@ class Pay
* *
* @return object [description] * @return object [description]
*/ */
private function createGateway($gateway) protected function createGateway($gateway)
{ {
if (!file_exists(__DIR__ . '/Gateways/' . ucfirst($this->drivers) . '/' . ucfirst($gateway) . 'Gateway.php')) { if (!file_exists(__DIR__ . '/Gateways/' . ucfirst($this->drivers) . '/' . ucfirst($gateway) . 'Gateway.php')) {
throw new InvalidArgumentException("Gateway [$gateway] is not supported."); throw new InvalidArgumentException("Gateway [$gateway] is not supported.");
@ -122,7 +122,7 @@ class Pay
* *
* @return object [description] * @return object [description]
*/ */
private function build($gateway) protected function build($gateway)
{ {
return new $gateway($this->config->get($this->drivers)); return new $gateway($this->config->get($this->drivers));
} }

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Alipay;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Alipay;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Alipay;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Wechat;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Wechat;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Wechat;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Wechat;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Gateways\Wechat;

View File

@ -2,8 +2,50 @@
namespace Yansongda\Pay\Tests; 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 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());
}
} }

View File

@ -0,0 +1,3 @@
<?php
namespace Yansongda\Pay\Tests\Support;

View File

@ -0,0 +1,4 @@
<?php
namespace Yansongda\Pay\Tests\Traits;