merge from v3

This commit is contained in:
yansongda 2021-07-21 11:43:18 +08:00
commit ab1adadb9a
12 changed files with 55 additions and 14 deletions

2
.gitattributes vendored
View File

@ -5,5 +5,5 @@
phpunit.php export-ignore
phpunit.xml export-ignore
phpunit.xml.dist export-ignore
.php_cs export-ignore
.php-cs-fixer.php export-ignore
.scrutinizer.yml export-ignore

View File

@ -10,8 +10,10 @@ class ContainerDependencyException extends ContainerException
{
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(string $message = 'Dependency Resolve Error', int $code = self::CONTAINER_DEPENDENCY_ERROR, array $extra = [], Throwable $previous = null)
public function __construct(string $message = 'Dependency Resolve Error', int $code = self::CONTAINER_DEPENDENCY_ERROR, $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -11,8 +11,10 @@ class ContainerException extends Exception implements ContainerExceptionInterfac
{
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(string $message = '', int $code = self::CONTAINER_ERROR, array $extra = [], Throwable $previous = null)
public function __construct(string $message = '', int $code = self::CONTAINER_ERROR, $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -10,8 +10,10 @@ class ContainerNotFoundException extends ContainerException
{
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(string $message = 'Container Not Found', int $code = self::CONTAINER_NOT_FOUND, array $extra = [], Throwable $previous = null)
public function __construct(string $message = 'Container Not Found', int $code = self::CONTAINER_NOT_FOUND, $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -88,14 +88,16 @@ class Exception extends \Exception
/**
* raw.
*
* @var array
* @var mixed
*/
public $extra = [];
public $extra = null;
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(string $message = 'Unknown Error', int $code = self::UNKNOWN_ERROR, array $extra = [], Throwable $previous = null)
public function __construct(string $message = 'Unknown Error', int $code = self::UNKNOWN_ERROR, $extra = null, Throwable $previous = null)
{
$this->extra = $extra;

View File

@ -8,7 +8,12 @@ use Throwable;
class InvalidConfigException extends Exception
{
public function __construct(int $code = self::CONFIG_ERROR, string $message = 'Config Error', array $extra = [], Throwable $previous = null)
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(int $code = self::CONFIG_ERROR, string $message = 'Config Error', $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -8,7 +8,12 @@ use Throwable;
class InvalidParamsException extends Exception
{
public function __construct(int $code = self::PARAMS_ERROR, string $message = 'Params Error', array $extra = [], Throwable $previous = null)
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(int $code = self::PARAMS_ERROR, string $message = 'Params Error', $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -18,10 +18,15 @@ class InvalidResponseException extends Exception
*/
public $response = [];
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(
int $code = self::RESPONSE_ERROR,
string $message = 'Provider response Error',
array $extra = [],
$extra = [],
?Throwable $exception = null,
Throwable $previous = null)
{

View File

@ -10,8 +10,10 @@ class ServiceException extends Exception
{
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(string $message = 'Service Error', int $code = self::SERVICE_ERROR, array $extra = [], Throwable $previous = null)
public function __construct(string $message = 'Service Error', int $code = self::SERVICE_ERROR, $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -11,8 +11,10 @@ class ServiceNotFoundException extends Exception implements NotFoundExceptionInt
{
/**
* Bootstrap.
*
* @param mixed $extra
*/
public function __construct(string $message = 'Service Not Found', int $code = self::SERVICE_NOT_FOUND_ERROR, array $extra = [], Throwable $previous = null)
public function __construct(string $message = 'Service Not Found', int $code = self::SERVICE_NOT_FOUND_ERROR, $extra = null, Throwable $previous = null)
{
parent::__construct($message, $code, $extra, $previous);
}

View File

@ -30,12 +30,15 @@ class InvokePrepayPlugin implements PluginInterface
Logger::info('[wechat][InvokePrepayPlugin] 插件开始装载', ['rocket' => $rocket]);
$prepayId = $rocket->getDestination()->get('prepay_id');
$config = $this->getInvokeConfig($rocket, $prepayId);
if (is_null($prepayId)) {
throw new InvalidResponseException(InvalidResponseException::RESPONSE_MISSING_NECESSARY_PARAMS);
Logger::error('[wechat][InvokePrepayPlugin] 预下单失败:响应缺少 prepay_id 参数', $rocket->getDestination()->all());
throw new InvalidResponseException(InvalidResponseException::RESPONSE_MISSING_NECESSARY_PARAMS, 'Prepay Response Error: Missing PrepayId', $rocket->getDestination()->all());
}
$config = $this->getInvokeConfig($rocket, $prepayId);
$rocket->setDestination($config);
Logger::info('[wechat][InvokePrepayPlugin] 插件装载完毕', ['rocket' => $rocket]);

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\Common;
use Yansongda\Pay\Exception\InvalidResponseException;
use Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayPlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
@ -21,4 +22,14 @@ class InvokePrepayPluginTest extends TestCase
self::assertArrayHasKey('package', $contents->all());
self::assertArrayHasKey('paySign', $contents->all());
}
public function testWrongPrepayId()
{
$rocket = (new Rocket())->setDestination(new Collection([]));
self::expectException(InvalidResponseException::class);
self::expectExceptionCode(InvalidResponseException::RESPONSE_MISSING_NECESSARY_PARAMS);
(new InvokePrepayPlugin())->assembly($rocket, function ($rocket) { return $rocket; });
}
}