1 | <?php |
||
15 | class InjectorTest extends \PHPUnit_Framework_TestCase |
||
16 | { |
||
17 | /** |
||
18 | * 正常系 |
||
19 | * 注入できること |
||
20 | * @test |
||
21 | */ |
||
22 | public function okInject() |
||
23 | { |
||
24 | $object = new Injected(); |
||
25 | $object->inject('key', 'value'); |
||
26 | $this->assertEquals($object->getValue("key"), "value"); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * 正常系 |
||
31 | * 型指定による注入ができること |
||
32 | * @test |
||
33 | */ |
||
34 | public function okStrictInject() |
||
35 | { |
||
36 | $object = new StrictInjected(); |
||
37 | $injectValue = new Sample1(); |
||
38 | $object->strictInject('value', $injectValue); |
||
39 | $this->assertInstanceOf("WebStream\DI\Test\Sample1", $object->getValue()); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * 正常系 |
||
44 | * 親クラスの型指定による注入ができること |
||
45 | * @test |
||
46 | */ |
||
47 | public function okParentClassStrictInject() |
||
48 | { |
||
49 | $object = new StrictInjected(); |
||
50 | $injectValue = new Sample3(); |
||
51 | $object->strictInject('value', $injectValue); |
||
52 | $this->assertInstanceOf("WebStream\DI\Test\Sample3", $object->getValue()); |
||
53 | $this->assertInstanceOf("WebStream\DI\Test\Sample1", $object->getValue()); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * 異常系 |
||
58 | * プロパティが定義していない場合、注入されず既定値が返ること |
||
59 | * @test |
||
60 | */ |
||
61 | public function ngUndefinedPropertyStrictInject() |
||
62 | { |
||
63 | $object = new StrictInjected(); |
||
64 | $injectValue = new Sample1(); |
||
65 | $object->strictInject('undefined', $injectValue); |
||
66 | $this->assertNull($object->getValue()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * 異常系 |
||
71 | * 定義された型と注入する型が不一致の場合、例外が発生すること |
||
72 | * @test |
||
73 | * @expectedException WebStream\Exception\Extend\AnnotationException |
||
74 | */ |
||
75 | public function ngMismatchTypeStrictInject() |
||
76 | { |
||
77 | $object = new StrictInjected(); |
||
78 | $injectValue = new Sample2(); |
||
79 | $object->strictInject('value', $injectValue); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * 異常系 |
||
84 | * NULL値を注入しようとした場合、例外が発生すること |
||
85 | * @test |
||
86 | * @expectedException WebStream\Exception\Extend\AnnotationException |
||
87 | */ |
||
88 | public function ngNullStrictInject() |
||
89 | { |
||
90 | $object = new StrictInjected(); |
||
91 | $object->strictInject('value', null); |
||
92 | } |
||
93 | } |
||
94 |