This commit is contained in:
yansongda 2021-06-07 14:38:27 +08:00
parent e320e5abc0
commit b11cd77422
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,56 @@
<?php
namespace Yansongda\Pay\Tests\Plugins;
use PHPUnit\Framework\TestCase;
use Yansongda\Pay\Contract\ParserInterface;
use Yansongda\Pay\Exception\InvalidConfigException;
use Yansongda\Pay\Parser\ArrayParser;
use Yansongda\Pay\Parser\NoHttpRequestParser;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\ParserPlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\Stubs\Packer\FooPackerStub;
class ParserPluginTest extends TestCase
{
public function testPackerWrong()
{
self::expectException(InvalidConfigException::class);
self::expectExceptionCode(InvalidConfigException::INVALID_PACKER);
Pay::config([]);
$rocket = new Rocket();
$rocket->setDirection(FooPackerStub::class);
$parser = new ParserPlugin();
$parser->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testPackerDefault()
{
Pay::config([]);
Pay::set(ParserInterface::class, NoHttpRequestParser::class);
$rocket = new Rocket();
$parser = new ParserPlugin();
$result = $parser->assembly($rocket, function ($rocket) { return $rocket; });
self::assertSame($rocket, $result);
}
public function testPackerObject()
{
Pay::config([]);
Pay::set(ParserInterface::class, new NoHttpRequestParser());
$rocket = new Rocket();
$parser = new ParserPlugin();
$result = $parser->assembly($rocket, function ($rocket) { return $rocket; });
self::assertSame($rocket, $result);
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace Yansongda\Pay\Tests\Stubs\Packer;
class FooPackerStub
{
}