Skip to content

Commit 0789b36

Browse files
committed
scope tests
1 parent 9ff9a0e commit 0789b36

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

src/AppTest.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Mvc5\App;
1010
use Mvc5\Config;
1111
use Mvc5\Plugin\Args;
12+
use Mvc5\Plugin\Callback;
13+
use Mvc5\Plugin\Invoke;
1214
use Mvc5\Plugin\Param;
1315
use Mvc5\Plugin\Plugin;
1416
use Mvc5\Plugin\Plugins;
@@ -118,6 +120,106 @@ function test_provider_and_scope()
118120
$this->assertEquals('foobar59360', $app->call('foo->bar->baz', ['param2' => '0']));
119121
}
120122

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+
121223
/**
122224
*
123225
*/

0 commit comments

Comments
 (0)