mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-03 05:52:48 +08:00
新增Instance测试用例
This commit is contained in:
67
tests/thinkphp/library/traits/think/instanceTest.php
Normal file
67
tests/thinkphp/library/traits/think/instanceTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace tests\thinkphp\library\traits\think;
|
||||
|
||||
use traits\think\Instance;
|
||||
|
||||
class instanceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testInstance()
|
||||
{
|
||||
$father = InstanceTestFather::instance();
|
||||
$this->assertInstanceOf('\tests\thinkphp\library\traits\think\InstanceTestFather', $father);
|
||||
$this->assertEquals([], $father->options);
|
||||
|
||||
$father2 = InstanceTestFather::instance(['father']);
|
||||
$this->assertEquals([], $father2->options);
|
||||
|
||||
$father2->options = ['father'];
|
||||
$this->assertEquals(['father'], $father->options);
|
||||
|
||||
$son = InstanceTestSon::instance(['son']);
|
||||
$this->assertInstanceOf('\tests\thinkphp\library\traits\think\InstanceTestFather', $son);
|
||||
$this->assertEquals(['father'], $son->options);
|
||||
}
|
||||
|
||||
public function testCallStatic()
|
||||
{
|
||||
$father = InstanceTestFather::instance();
|
||||
$this->assertEquals([], $father->options);
|
||||
|
||||
$this->assertEquals($father::__protectedStaticFunc(['thinkphp']), 'protectedStaticFunc["thinkphp"]');
|
||||
|
||||
try {
|
||||
$father::_protectedStaticFunc();
|
||||
$this->setExpectedException('\think\Exception');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\think\Exception', $e);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
call_user_func(\Closure::bind(function () {
|
||||
InstanceTestFather::$instance = null;
|
||||
}, null, '\tests\thinkphp\library\traits\think\InstanceTestFather'));
|
||||
}
|
||||
}
|
||||
|
||||
class InstanceTestFather
|
||||
{
|
||||
use Instance;
|
||||
|
||||
public $options = null;
|
||||
|
||||
public function __construct($options)
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
protected static function _protectedStaticFunc($params)
|
||||
{
|
||||
return 'protectedStaticFunc' . json_encode($params);
|
||||
}
|
||||
}
|
||||
|
||||
class InstanceTestSon extends InstanceTestFather
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user