9
9
use Mvc5 \Config ;
10
10
use Mvc5 \Plugin \Maybe ;
11
11
use Mvc5 \Plugin \Nothing ;
12
+ use Mvc5 \Plugin \Nullable ;
13
+ use Mvc5 \Plugin \Plugin ;
12
14
use Mvc5 \Plugin \Shared ;
13
15
use Mvc5 \Test \Test \TestCase ;
14
16
@@ -201,7 +203,7 @@ function test_nothing_isset()
201
203
$ app ['foo ' ] = new Nothing ;
202
204
203
205
$ this ->assertTrue (isset ($ app ['foo ' ]));
204
- $ this ->assertNull ($ app ['foo ' ]);
206
+ $ this ->assertNull (Maybe:: nullable ( $ app ['foo ' ]) );
205
207
}
206
208
207
209
/**
@@ -226,13 +228,14 @@ function test_shared_method_returns_nothing()
226
228
227
229
$ app = new App ;
228
230
229
- $ this -> assertNull ( $ app ->shared ('foo ' , function () use (&$ count ) {
231
+ $ foo = $ app ->shared ('foo ' , function () use (&$ count ) {
230
232
++$ count ;
231
233
return new Nothing ;
232
- })) ;
234
+ });
233
235
234
- $ this ->assertNull ($ app ->get ('foo ' ));
235
- $ this ->assertNull ($ app ->shared ('foo ' ));
236
+ $ this ->assertInstanceOf (Nothing::class, $ foo );
237
+ $ this ->assertNull (Maybe::nullable ($ app ->get ('foo ' )));
238
+ $ this ->assertNull (Maybe::nullable ($ app ->shared ('foo ' )));
236
239
$ this ->assertEquals (1 , $ count );
237
240
}
238
241
@@ -258,16 +261,17 @@ function test_shared_maybe_plugin_returns_nothing()
258
261
$ count = 0 ;
259
262
260
263
$ app = new App (['services ' => [
261
- 'foo ' => new Shared ( ' foo ' , new Maybe (function () use (&$ count ) {
264
+ 'foo ' => new Maybe (function () use (&$ count ) {
262
265
++$ count ;
263
266
return new Nothing ;
264
- }))
267
+ }),
268
+ 'foobar ' => new Nullable (new Shared ('foo ' ))
265
269
]]);
266
270
267
- $ this ->assertNull ($ app ->plugin ('foo ' ));
268
- $ this ->assertNull ($ app ->shared ('foo ' ));
269
- $ this ->assertNull ($ app ->get ('foo ' ));
270
- $ this ->assertNull ($ app ['foo ' ]);
271
+ $ this ->assertNull ($ app ->plugin ('foobar ' ));
272
+ $ this ->assertNull ($ app ->shared ('foobar ' ));
273
+ $ this ->assertNull ($ app ->get ('foobar ' ));
274
+ $ this ->assertNull ($ app ['foobar ' ]);
271
275
$ this ->assertEquals (1 , $ count );
272
276
}
273
277
@@ -279,16 +283,17 @@ function test_shared_maybe_plugin_returns_null()
279
283
$ count = 0 ;
280
284
281
285
$ app = new App (['services ' => [
282
- 'foo ' => new Shared ( ' foo ' , new Maybe (function () use (&$ count ) {
286
+ 'foo ' => new Maybe (function () use (&$ count ) {
283
287
++$ count ;
284
288
return null ;
285
- }))
289
+ }),
290
+ 'foobar ' => new Nullable (new Shared ('foo ' ))
286
291
]]);
287
292
288
- $ this ->assertNull ($ app ->plugin ('foo ' ));
289
- $ this ->assertNull ($ app ->shared ('foo ' ));
290
- $ this ->assertNull ($ app ->get ('foo ' ));
291
- $ this ->assertNull ($ app ['foo ' ]);
293
+ $ this ->assertNull ($ app ->plugin ('foobar ' ));
294
+ $ this ->assertNull ($ app ->shared ('foobar ' ));
295
+ $ this ->assertNull ($ app ->get ('foobar ' ));
296
+ $ this ->assertNull ($ app ['foobar ' ]);
292
297
$ this ->assertEquals (1 , $ count );
293
298
}
294
299
@@ -303,12 +308,13 @@ function test_shared_plugin_returns_nothing()
303
308
'foo ' => new Shared ('foo ' , function () use (&$ count ) {
304
309
++$ count ;
305
310
return new Nothing ;
306
- })
311
+ }),
312
+ 'foobar ' => new Nullable (new Plugin ('foo ' ))
307
313
]]);
308
314
309
- $ this ->assertNull ($ app ->plugin ('foo ' ));
310
- $ this ->assertNull ($ app ->shared ('foo ' ));
311
- $ this ->assertNull ($ app ->get ('foo ' ));
315
+ $ this ->assertNull ($ app ->plugin ('foobar ' ));
316
+ $ this ->assertNull ($ app ->shared ('foobar ' ));
317
+ $ this ->assertNull (Maybe:: nullable ( $ app ->get ('foo ' ) ));
312
318
$ this ->assertEquals (1 , $ count );
313
319
}
314
320
0 commit comments