1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: reallyli |
5
|
|
|
* Date: 18/10/11 |
6
|
|
|
* Time: 下午2:39. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Reallyli\LaravelUnicomponent\Tests; |
10
|
|
|
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Reallyli\LaravelUnicomponent\Components\Pusher\Pusher; |
13
|
|
|
use Reallyli\LaravelUnicomponent\Tests\Example\ExampleService; |
14
|
|
|
use Reallyli\LaravelUnicomponent\UnicomponentServiceManager; |
15
|
|
|
|
16
|
|
|
class UnicomponentTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Method description:Test Register Component. |
20
|
|
|
* |
21
|
|
|
* @author reallyli <[email protected]> |
22
|
|
|
* @since 18/10/11 |
23
|
|
|
* @return mixed |
24
|
|
|
* 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值) |
25
|
|
|
*/ |
26
|
|
|
public function testRegisterComponent() |
27
|
|
|
{ |
28
|
|
|
$unicomponentServiceManager = new UnicomponentServiceManager([]); |
29
|
|
|
|
30
|
|
|
$unicomponentServiceManager->registerComponent(new ExampleService()); |
31
|
|
|
|
32
|
|
|
$this->assertEquals('test', $unicomponentServiceManager->example()->test()); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Method description:testConfigurationComponents. |
37
|
|
|
* |
38
|
|
|
* @author reallyli <[email protected]> |
39
|
|
|
* @since 18/10/11 |
40
|
|
|
* @return mixed |
41
|
|
|
* 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值) |
42
|
|
|
*/ |
43
|
|
|
public function testConfigurationComponents() |
44
|
|
|
{ |
45
|
|
|
$unicompoentConfig = include_once __DIR__.'/unicomponentConfig.php'; |
46
|
|
|
$unicomponentServiceManager = new UnicomponentServiceManager($unicompoentConfig); |
47
|
|
|
|
48
|
|
|
$this->assertClassHasAttribute('test', get_class($unicomponentServiceManager->example())); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Method description:Test Get Component. |
53
|
|
|
* |
54
|
|
|
* @author reallyli <[email protected]> |
55
|
|
|
* @since 18/10/11 |
56
|
|
|
* @return mixed |
57
|
|
|
* 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值) |
58
|
|
|
*/ |
59
|
|
|
public function testGetComponent() |
60
|
|
|
{ |
61
|
|
|
$unicompoentConfig = include_once __DIR__.'/../config/unicomponent.php'; |
62
|
|
|
|
63
|
|
|
$unicomponentServiceManager = new UnicomponentServiceManager($unicompoentConfig); |
64
|
|
|
|
65
|
|
|
$this->assertInstanceOf(Pusher::class, $unicomponentServiceManager->pusher); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: