Skip to content

Commit

Permalink
Added route test
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Jun 25, 2020
1 parent 9d3e6ad commit dc6558e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ public function testExecute()

public function tearDown()
{
$this->view = null;
$this->app = null;
}
}
97 changes: 97 additions & 0 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Utopia PHP Framework
*
* @package Framework
* @subpackage Tests
*
* @link https://github.com/utopia-php/framework
* @author Appwrite Team <[email protected]>
* @version 1.0 RC4
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/

namespace Utopia;

use PHPUnit\Framework\TestCase;
use Utopia\Validator\Text;

class RouteTest extends TestCase
{
/**
* @var Route
*/
protected $route = null;

public function setUp()
{
$this->route = new Route('GET', '/');
}

public function testMethod()
{
$this->assertEquals('GET', $this->route->getMethod());
}

public function testURL()
{
$this->assertEquals('/', $this->route->getURL());

$this->route->URL('/path');

$this->assertEquals('/path', $this->route->getURL());
}

public function testDesc()
{
$this->assertEquals('', $this->route->getDesc());

$this->route->desc('new route');

$this->assertEquals('new route', $this->route->getDesc());
}

public function testGroups()
{
$this->assertEquals([], $this->route->getGroups());

$this->route->groups(['api', 'homepage']);

$this->assertEquals(['api', 'homepage'], $this->route->getGroups());
}

public function testAction()
{
$this->assertEquals(null, $this->route->getAction());

$this->route->action(function() {return 'hello world';});

$this->assertEquals('hello world', $this->route->getAction()());
}

public function testParam()
{
$this->assertEquals([], $this->route->getParams());

$this->route
->param('x', '', new Text(10))
->param('y', '', new Text(10))
;

$this->assertCount(2, $this->route->getParams());
}

public function testLabel()
{
$this->assertEquals('default', $this->route->getLabel('key', 'default'));

$this->route->label('key', 'value');

$this->assertEquals('value', $this->route->getLabel('key', 'default'));
}

public function tearDown()
{
$this->route = null;
}
}

0 comments on commit dc6558e

Please sign in to comment.