Skip to content

Commit 82c787c

Browse files
committed
Add test for ActionRoute
1 parent 62da11b commit 82c787c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/*
3+
* This file is part of the cortex package.
4+
*
5+
* (c) Giuseppe Mazzapica <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Brain\Cortex\Tests\Unit\Route;
12+
13+
use Brain\Cortex\Controller\QueryVarsController;
14+
use Brain\Cortex\Route\ActionRoute;
15+
use Brain\Cortex\Route\QueryRoute;
16+
use Brain\Cortex\Tests\TestCase;
17+
18+
/**
19+
* @author Giuseppe Mazzapica <[email protected]>
20+
* @license http://opensource.org/licenses/MIT MIT
21+
* @package cortex
22+
*/
23+
class ActionRouteTest extends TestCase
24+
{
25+
public function testArrayAccess()
26+
{
27+
$handler = function (array $vars) {
28+
return $vars;
29+
};
30+
31+
$route = new ActionRoute('foo/bar', $handler, [
32+
'foo',
33+
1,
34+
'vars' => [],
35+
'path' => '/',
36+
'meh' => 'meh',
37+
'priority' => 0
38+
]);
39+
40+
assertFalse($route->offsetExists('foo'));
41+
assertNull($route->offsetGet('meh'));
42+
assertTrue($route->offsetExists('id')); // id is auto generated
43+
assertSame(0, $route->offsetGet('priority'));
44+
assertSame('foo/bar', $route->offsetGet('path'));
45+
assertSame([], $route->offsetGet('vars'));
46+
assertInternalType('callable', $route->offsetGet('handler'));
47+
48+
unset($route['path']);
49+
$route['priority'] = 1;
50+
$route->offsetUnset('id');
51+
$route->offsetUnset('vars');
52+
53+
assertNull($route->offsetGet('path'));
54+
assertSame(1, $route->offsetGet('priority'));
55+
assertTrue($route->offsetExists('id')); // id cannot be unset
56+
assertFalse($route->offsetExists('vars'));
57+
}
58+
}

0 commit comments

Comments
 (0)