Skip to content

Commit

Permalink
Add test for ActionRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Feb 29, 2016
1 parent 62da11b commit 82c787c
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/src/Unit/Route/ActionRouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/*
* This file is part of the cortex package.
*
* (c) Giuseppe Mazzapica <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Brain\Cortex\Tests\Unit\Route;

use Brain\Cortex\Controller\QueryVarsController;
use Brain\Cortex\Route\ActionRoute;
use Brain\Cortex\Route\QueryRoute;
use Brain\Cortex\Tests\TestCase;

/**
* @author Giuseppe Mazzapica <[email protected]>
* @license http://opensource.org/licenses/MIT MIT
* @package cortex
*/
class ActionRouteTest extends TestCase
{
public function testArrayAccess()
{
$handler = function (array $vars) {
return $vars;
};

$route = new ActionRoute('foo/bar', $handler, [
'foo',
1,
'vars' => [],
'path' => '/',
'meh' => 'meh',
'priority' => 0
]);

assertFalse($route->offsetExists('foo'));
assertNull($route->offsetGet('meh'));
assertTrue($route->offsetExists('id')); // id is auto generated
assertSame(0, $route->offsetGet('priority'));
assertSame('foo/bar', $route->offsetGet('path'));
assertSame([], $route->offsetGet('vars'));
assertInternalType('callable', $route->offsetGet('handler'));

unset($route['path']);
$route['priority'] = 1;
$route->offsetUnset('id');
$route->offsetUnset('vars');

assertNull($route->offsetGet('path'));
assertSame(1, $route->offsetGet('priority'));
assertTrue($route->offsetExists('id')); // id cannot be unset
assertFalse($route->offsetExists('vars'));
}
}

0 comments on commit 82c787c

Please sign in to comment.