|
9 | 9 | use Mvc5\App;
|
10 | 10 | use Mvc5\Config;
|
11 | 11 | use Mvc5\Plugin\Args;
|
| 12 | +use Mvc5\Plugin\Callback; |
| 13 | +use Mvc5\Plugin\Invoke; |
12 | 14 | use Mvc5\Plugin\Param;
|
13 | 15 | use Mvc5\Plugin\Plugin;
|
14 | 16 | use Mvc5\Plugin\Plugins;
|
@@ -118,6 +120,106 @@ function test_provider_and_scope()
|
118 | 120 | $this->assertEquals('foobar59360', $app->call('foo->bar->baz', ['param2' => '0']));
|
119 | 121 | }
|
120 | 122 |
|
| 123 | + /** |
| 124 | + * @throws \Throwable |
| 125 | + */ |
| 126 | + function test_provider_scope() |
| 127 | + { |
| 128 | + $app = new App([ |
| 129 | + 'services' => [ |
| 130 | + 'bar' => function() { |
| 131 | + return $this; |
| 132 | + }, |
| 133 | + 'foo' => new Plugin('bar') |
| 134 | + ] |
| 135 | + ], null, true); |
| 136 | + |
| 137 | + $this->assertEquals($app, $app->plugin('bar')); |
| 138 | + $this->assertEquals($this, $app->plugin('foo')); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * @throws \Throwable |
| 143 | + */ |
| 144 | + function test_provider_custom_scope() |
| 145 | + { |
| 146 | + $config = new Config; |
| 147 | + |
| 148 | + $app = new App([ |
| 149 | + 'services' => [ |
| 150 | + 'bar' => function() { |
| 151 | + return $this; |
| 152 | + }, |
| 153 | + 'foo' => new Plugin('bar') |
| 154 | + ] |
| 155 | + ], null, $config); |
| 156 | + |
| 157 | + $this->assertEquals($config, $app->plugin('bar')); |
| 158 | + $this->assertEquals($this, $app->plugin('foo')); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * @throws \Throwable |
| 163 | + */ |
| 164 | + function test_provider_callable_closure_scope() |
| 165 | + { |
| 166 | + $app = new App([ |
| 167 | + 'services' => [ |
| 168 | + 'bar' => new Callback(function() { |
| 169 | + return $this; |
| 170 | + }), |
| 171 | + 'foo' => new Invoke(function() { |
| 172 | + return $this; |
| 173 | + }), |
| 174 | + ] |
| 175 | + ], null, true); |
| 176 | + |
| 177 | + $this->assertEquals($app, $app->plugin('bar')()); |
| 178 | + $this->assertEquals($this, $app->plugin('foo')()); |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * @throws \Throwable |
| 183 | + */ |
| 184 | + function test_provider_callable_closure_custom_scope() |
| 185 | + { |
| 186 | + $config = new Config; |
| 187 | + |
| 188 | + $app = new App([ |
| 189 | + 'services' => [ |
| 190 | + 'bar' => new Callback(function() { |
| 191 | + return $this; |
| 192 | + }), |
| 193 | + 'foo' => new Invoke(function() { |
| 194 | + return $this; |
| 195 | + }), |
| 196 | + ] |
| 197 | + ], null, $config); |
| 198 | + |
| 199 | + $this->assertEquals($config, $app->plugin('bar')()); |
| 200 | + $this->assertEquals($this, $app->plugin('foo')()); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * @throws \Throwable |
| 205 | + */ |
| 206 | + function test_provider_callable_closure_without_scope() |
| 207 | + { |
| 208 | + $app = new App([ |
| 209 | + 'services' => [ |
| 210 | + 'bar' => new Callback(function() { |
| 211 | + return $this; |
| 212 | + }), |
| 213 | + 'foo' => new Invoke(function() { |
| 214 | + return $this; |
| 215 | + }), |
| 216 | + ] |
| 217 | + ]); |
| 218 | + |
| 219 | + $this->assertEquals($this, $app->plugin('bar')()); |
| 220 | + $this->assertEquals($this, $app->plugin('foo')()); |
| 221 | + } |
| 222 | + |
121 | 223 | /**
|
122 | 224 | *
|
123 | 225 | */
|
|
0 commit comments