|
1
|
|
|
<?php |
|
2
|
|
|
namespace tests\thinkphp\library\traits\think; |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
use traits\think\Instance; |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class instanceTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
public function testInstance() |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
$father = InstanceTestFather::instance(); |
|
11
|
|
|
$this->assertInstanceOf('\tests\thinkphp\library\traits\think\InstanceTestFather', $father); |
|
12
|
|
|
$this->assertEquals([], $father->options); |
|
13
|
|
|
|
|
14
|
|
|
$son = InstanceTestFather::instance(['son']); |
|
15
|
|
|
$this->assertSame($father, $son); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testCallStatic() |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
$father = InstanceTestFather::instance(); |
|
21
|
|
|
$this->assertEquals([], $father->options); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertEquals($father::__protectedStaticFunc(['thinkphp']), 'protectedStaticFunc["thinkphp"]'); |
|
24
|
|
|
|
|
25
|
|
|
try { |
|
26
|
|
|
$father::_protectedStaticFunc(); |
|
27
|
|
|
$this->setExpectedException('\think\Exception'); |
|
28
|
|
|
} catch (\Exception $e) { |
|
29
|
|
|
$this->assertInstanceOf('\think\Exception', $e); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function tearDown() |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
call_user_func(\Closure::bind(function () { |
|
|
|
|
|
|
36
|
|
|
InstanceTestFather::$instance = null; |
|
37
|
|
|
}, null, '\tests\thinkphp\library\traits\think\InstanceTestFather')); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
class InstanceTestFather |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
use Instance; |
|
44
|
|
|
|
|
45
|
|
|
public $options = null; |
|
46
|
|
|
|
|
47
|
|
|
public function __construct($options) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$this->options = $options; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected static function _protectedStaticFunc($params) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return 'protectedStaticFunc' . json_encode($params); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
class InstanceTestSon extends InstanceTestFather |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
} |
|
61
|
|
|
|