Skip to content

Commit cde20b5

Browse files
committed
maybe nullable
1 parent 0fc4447 commit cde20b5

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

src/Plugin/MaybeTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Mvc5\App;
99
use Mvc5\Plugin\Maybe;
1010
use Mvc5\Plugin\Nothing;
11+
use Mvc5\Plugin\Nullable;
12+
use Mvc5\Plugin\Plugin;
1113
use Mvc5\Test\Test\TestCase;
1214

1315
class MaybeTest
@@ -54,13 +56,14 @@ function test_plugin_returns_false()
5456
function test_plugin_returns_nothing()
5557
{
5658
$app = new App(['services' => [
57-
'foo' => new Maybe(new Nothing)
59+
'foo' => new Nothing,
60+
'foobar' => new Nullable(new Plugin('foo'))
5861
]]);
5962

6063
$this->assertInstanceOf(Nothing::class, $app->plugin('foo'));
61-
$this->assertNull($app['foo']);
62-
$this->assertNull($app->get('foo'));
63-
$this->assertNull($app->shared('foo'));
64+
$this->assertInstanceOf(Nothing::class, $app->shared('foo'));
65+
$this->assertNull($app['foobar']);
66+
$this->assertNull($app->get('foobar'));
6467
}
6568

6669
/**
@@ -69,10 +72,12 @@ function test_plugin_returns_nothing()
6972
function test_plugin_returns_null()
7073
{
7174
$app = new App(['services' => [
72-
'foo' => new Maybe(null)
75+
'foo' => new Maybe(null),
76+
'foobar' => new Nullable(new Plugin('foo'))
7377
]]);
7478

75-
$this->assertNull($app['foo']);
79+
$this->assertNull($app['foobar']);
80+
$this->assertInstanceOf(Nothing::class, $app['foo']);
7681
$this->assertInstanceOf(Nothing::class, $app->plugin('foo'));
7782
}
7883

src/Resolver/ContainerTest.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Mvc5\Config;
1010
use Mvc5\Plugin\Maybe;
1111
use Mvc5\Plugin\Nothing;
12+
use Mvc5\Plugin\Nullable;
13+
use Mvc5\Plugin\Plugin;
1214
use Mvc5\Plugin\Shared;
1315
use Mvc5\Test\Test\TestCase;
1416

@@ -201,7 +203,7 @@ function test_nothing_isset()
201203
$app['foo'] = new Nothing;
202204

203205
$this->assertTrue(isset($app['foo']));
204-
$this->assertNull($app['foo']);
206+
$this->assertNull(Maybe::nullable($app['foo']));
205207
}
206208

207209
/**
@@ -226,13 +228,14 @@ function test_shared_method_returns_nothing()
226228

227229
$app = new App;
228230

229-
$this->assertNull($app->shared('foo', function() use(&$count) {
231+
$foo = $app->shared('foo', function() use(&$count) {
230232
++$count;
231233
return new Nothing;
232-
}));
234+
});
233235

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')));
236239
$this->assertEquals(1, $count);
237240
}
238241

@@ -258,16 +261,17 @@ function test_shared_maybe_plugin_returns_nothing()
258261
$count = 0;
259262

260263
$app = new App(['services' => [
261-
'foo' => new Shared('foo', new Maybe(function() use (&$count) {
264+
'foo' => new Maybe(function() use (&$count) {
262265
++$count;
263266
return new Nothing;
264-
}))
267+
}),
268+
'foobar' => new Nullable(new Shared('foo'))
265269
]]);
266270

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']);
271275
$this->assertEquals(1, $count);
272276
}
273277

@@ -279,16 +283,17 @@ function test_shared_maybe_plugin_returns_null()
279283
$count = 0;
280284

281285
$app = new App(['services' => [
282-
'foo' => new Shared('foo', new Maybe(function() use (&$count) {
286+
'foo' => new Maybe(function() use (&$count) {
283287
++$count;
284288
return null;
285-
}))
289+
}),
290+
'foobar' => new Nullable(new Shared('foo'))
286291
]]);
287292

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']);
292297
$this->assertEquals(1, $count);
293298
}
294299

@@ -303,12 +308,13 @@ function test_shared_plugin_returns_nothing()
303308
'foo' => new Shared('foo', function() use(&$count) {
304309
++$count;
305310
return new Nothing;
306-
})
311+
}),
312+
'foobar' => new Nullable(new Plugin('foo'))
307313
]]);
308314

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')));
312318
$this->assertEquals(1, $count);
313319
}
314320

0 commit comments

Comments
 (0)