mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-02 12:17:38 +08:00
增加单元测试
This commit is contained in:
parent
007ded7a1f
commit
74c07048c6
@ -72,7 +72,7 @@ class Config implements ArrayAccess
|
||||
*/
|
||||
public function set(string $key, $value)
|
||||
{
|
||||
if (is_null($key) || $key == '') {
|
||||
if ($key == '') {
|
||||
throw new InvalidArgumentException('Invalid config key.');
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ class Config implements ArrayAccess
|
||||
$this->config[$keys[0]][$keys[1]] = $value;
|
||||
break;
|
||||
case '3':
|
||||
$this->config[$keys[0]][$keys[1]][$keys[3]] = $value;
|
||||
$this->config[$keys[0]][$keys[1]][$keys[2]] = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1,3 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Tests\Support;
|
||||
|
||||
use Yansongda\Pay\Tests\TestCase;
|
||||
use Yansongda\Pay\Support\Config;
|
||||
use Yansongda\Pay\Exceptions\InvalidArgumentException;
|
||||
|
||||
class ConfigTest extends TestCase
|
||||
{
|
||||
public function testGetConfig()
|
||||
{
|
||||
$array = [
|
||||
'foo' => 'bar',
|
||||
'bar' => [
|
||||
'id' => '18',
|
||||
'key' => [
|
||||
'public' => 'qwer',
|
||||
'private' => 'asdf',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$config = new Config($array);
|
||||
|
||||
$this->assertTrue(isset($config['foo']));
|
||||
|
||||
$this->assertSame('bar', $config['foo']);
|
||||
$this->assertSame('bar', $config->get('foo'));
|
||||
$this->assertSame($array, $config->get());
|
||||
|
||||
$this->assertSame('qwer', $config->get('bar.key.public'));
|
||||
$this->assertNull($config->get('bar.key.public.foo'));
|
||||
$this->assertNull($config->get('bar.foo.foo.foo'));
|
||||
}
|
||||
|
||||
public function testSetConfig()
|
||||
{
|
||||
$config = new Config([]);
|
||||
|
||||
$this->assertArrayHasKey('foo', $config->set('foo', 'bar'));
|
||||
$this->assertSame('bar', $config->get('foo'));
|
||||
|
||||
$this->assertArrayHasKey('bar', $config->set('bar.key.public', 'qwer'));
|
||||
$this->assertSame('qwer', $config->get('bar.key.public'));
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid config key.');
|
||||
$config->set('', '');
|
||||
$this->assertArrayHasKey('error', $config->set('error.foo.foo.foo.foo', 'foo'));
|
||||
}
|
||||
}
|
@ -2,3 +2,11 @@
|
||||
|
||||
namespace Yansongda\Pay\Tests\Traits;
|
||||
|
||||
use Yansongda\Pay\Tests\TestCase;
|
||||
use Yansongda\Pay\Exceptions\InvalidArgumentException;
|
||||
|
||||
class HasHttpRequestTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user