Skip to content

Commit 997316a

Browse files
committed
tidy up
1 parent cde20b5 commit 997316a

File tree

5 files changed

+84
-165
lines changed

5 files changed

+84
-165
lines changed

src/Plugin/FilterTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,4 @@ function($foo, $baz, $bar) {
152152

153153
$this->assertNull($app->plugin(new Filter('foo', new Param('filters.foo'), ['bar']), ['s']));
154154
}
155-
156-
/**
157-
*
158-
*/
159-
function test_resolvable_closure()
160-
{
161-
$maybe = new Filter(function() {});
162-
163-
$this->assertInstanceOf(Call::class, $maybe->config());
164-
}
165155
}

src/Plugin/MaybeTest.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,8 @@ function test()
2222
{
2323
$maybe = new Maybe('foo');
2424

25-
$this->assertEquals('foo', $maybe->config());
26-
$this->assertEquals([], $maybe->args());
27-
$this->assertEquals([[Maybe::class, 'nothing']], $maybe->filter());
28-
$this->assertNull($maybe->param());
29-
}
30-
31-
/**
32-
*
33-
*/
34-
function test_nothing()
35-
{
36-
$this->assertEquals('foo', Maybe::nothing('foo'));
37-
$this->assertInstanceOf(Nothing::class, Maybe::nothing(null));
25+
$this->assertEquals([$maybe, '__invoke'], $maybe->config());
26+
$this->assertEquals(['foo'], $maybe->args());
3827
}
3928

4029
/**
@@ -50,22 +39,6 @@ function test_plugin_returns_false()
5039
$this->assertFalse($app->plugin('foo'));
5140
}
5241

53-
/**
54-
*
55-
*/
56-
function test_plugin_returns_nothing()
57-
{
58-
$app = new App(['services' => [
59-
'foo' => new Nothing,
60-
'foobar' => new Nullable(new Plugin('foo'))
61-
]]);
62-
63-
$this->assertInstanceOf(Nothing::class, $app->plugin('foo'));
64-
$this->assertInstanceOf(Nothing::class, $app->shared('foo'));
65-
$this->assertNull($app['foobar']);
66-
$this->assertNull($app->get('foobar'));
67-
}
68-
6942
/**
7043
*
7144
*/

src/Plugin/NothingTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Mvc5\Test\Plugin;
7+
8+
use Mvc5\App;
9+
use Mvc5\Plugin\Nothing;
10+
use Mvc5\Test\Test\TestCase;
11+
12+
class NothingTest
13+
extends TestCase
14+
{
15+
/**
16+
*
17+
*/
18+
function test()
19+
{
20+
$app = new App;
21+
22+
$app['foo'] = new Nothing;
23+
24+
$this->assertTrue(isset($app['foo']));
25+
$this->assertInstanceOf(Nothing::class, $app['foo']);
26+
}
27+
}

src/Plugin/NullableTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Mvc5\Test\Plugin;
7+
8+
use Mvc5\App;
9+
use Mvc5\Plugin\Call;
10+
use Mvc5\Plugin\Maybe;
11+
use Mvc5\Plugin\Nullable;
12+
use Mvc5\Plugin\Shared;
13+
use Mvc5\Test\Test\TestCase;
14+
15+
class NullableTest
16+
extends TestCase
17+
{
18+
/**
19+
*
20+
*/
21+
function test()
22+
{
23+
$maybe = new Nullable('foo');
24+
25+
$this->assertEquals([$maybe, '__invoke'], $maybe->config());
26+
$this->assertEquals(['foo'], $maybe->args());
27+
}
28+
29+
/**
30+
*
31+
*/
32+
function test_shared_null_value()
33+
{
34+
$count = 0;
35+
36+
$app = new App(['services' => [
37+
'foo' => new Maybe(new Call(function() use (&$count) {
38+
++$count;
39+
return null;
40+
})),
41+
'foobar' => new Nullable(new Shared('foo'))
42+
]]);
43+
44+
$this->assertNull($app->plugin('foobar'));
45+
$this->assertNull($app->shared('foobar'));
46+
$this->assertNull($app->get('foobar'));
47+
$this->assertNull($app['foobar']);
48+
$this->assertEquals(1, $count);
49+
}
50+
}

src/Resolver/ContainerTest.php

Lines changed: 5 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
use Mvc5\App;
99
use Mvc5\Config;
10-
use Mvc5\Plugin\Maybe;
11-
use Mvc5\Plugin\Nothing;
12-
use Mvc5\Plugin\Nullable;
13-
use Mvc5\Plugin\Plugin;
14-
use Mvc5\Plugin\Shared;
1510
use Mvc5\Test\Test\TestCase;
1611

1712
class ContainerTest
@@ -193,19 +188,6 @@ function test_next_iterator()
193188
$this->assertEquals('bat', $app->current());
194189
}
195190

196-
/**
197-
*
198-
*/
199-
function test_nothing_isset()
200-
{
201-
$app = new App;
202-
203-
$app['foo'] = new Nothing;
204-
205-
$this->assertTrue(isset($app['foo']));
206-
$this->assertNull(Maybe::nullable($app['foo']));
207-
}
208-
209191
/**
210192
*
211193
*/
@@ -222,120 +204,17 @@ function test_null_not_isset()
222204
/**
223205
*
224206
*/
225-
function test_shared_method_returns_nothing()
226-
{
227-
$count = 0;
228-
229-
$app = new App;
230-
231-
$foo = $app->shared('foo', function() use(&$count) {
232-
++$count;
233-
return new Nothing;
234-
});
235-
236-
$this->assertInstanceOf(Nothing::class, $foo);
237-
$this->assertNull(Maybe::nullable($app->get('foo')));
238-
$this->assertNull(Maybe::nullable($app->shared('foo')));
239-
$this->assertEquals(1, $count);
240-
}
241-
242-
/**
243-
*
244-
*/
245-
function test_shared_method_returns_null()
207+
function test_null_unset()
246208
{
247209
$app = new App;
248210

249-
$this->assertNull($app->shared('foo', function() {
250-
return null;
251-
}));
211+
$app['foo'] = 'foobar';
252212

253-
$this->assertFalse($app->has('foo'));
254-
}
213+
$this->assertEquals('foobar', $app['foo']);
255214

256-
/**
257-
*
258-
*/
259-
function test_shared_maybe_plugin_returns_nothing()
260-
{
261-
$count = 0;
262-
263-
$app = new App(['services' => [
264-
'foo' => new Maybe(function() use (&$count) {
265-
++$count;
266-
return new Nothing;
267-
}),
268-
'foobar' => new Nullable(new Shared('foo'))
269-
]]);
270-
271-
$this->assertNull($app->plugin('foobar'));
272-
$this->assertNull($app->shared('foobar'));
273-
$this->assertNull($app->get('foobar'));
274-
$this->assertNull($app['foobar']);
275-
$this->assertEquals(1, $count);
276-
}
277-
278-
/**
279-
*
280-
*/
281-
function test_shared_maybe_plugin_returns_null()
282-
{
283-
$count = 0;
284-
285-
$app = new App(['services' => [
286-
'foo' => new Maybe(function() use (&$count) {
287-
++$count;
288-
return null;
289-
}),
290-
'foobar' => new Nullable(new Shared('foo'))
291-
]]);
292-
293-
$this->assertNull($app->plugin('foobar'));
294-
$this->assertNull($app->shared('foobar'));
295-
$this->assertNull($app->get('foobar'));
296-
$this->assertNull($app['foobar']);
297-
$this->assertEquals(1, $count);
298-
}
299-
300-
/**
301-
*
302-
*/
303-
function test_shared_plugin_returns_nothing()
304-
{
305-
$count = 0;
306-
307-
$app = new App(['services' => [
308-
'foo' => new Shared('foo', function() use(&$count) {
309-
++$count;
310-
return new Nothing;
311-
}),
312-
'foobar' => new Nullable(new Plugin('foo'))
313-
]]);
314-
315-
$this->assertNull($app->plugin('foobar'));
316-
$this->assertNull($app->shared('foobar'));
317-
$this->assertNull(Maybe::nullable($app->get('foo')));
318-
$this->assertEquals(1, $count);
319-
}
320-
321-
/**
322-
*
323-
*/
324-
function test_shared_plugin_returns_null()
325-
{
326-
$count = 0;
327-
328-
$app = new App(['services' => [
329-
'foo' => new Shared('foo', function() use(&$count) {
330-
++$count;
331-
return null;
332-
})
333-
]]);
215+
$app['foo'] = null;
334216

335-
$this->assertNull($app->plugin('foo'));
336-
$this->assertNull($app->shared('foo'));
337-
$this->assertNull($app->get('foo'));
338-
$this->assertEquals(3, $count);
217+
$this->assertNull($app['foo']);
339218
}
340219

341220
/**

0 commit comments

Comments
 (0)