Skip to content

Commit

Permalink
Merge branch 'release/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kayalion committed Sep 16, 2016
2 parents 66c0fa5 + 41b8a32 commit b5acf42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/ride/library/router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ protected function setPath($path) {
throw new RouterException('Could not set the path of the route: ' . $path . ' is not a valid HTTP path');
}

$this->path = '/' . trim($path, '/');
if (substr($path, 0, 1) != '/') {
$path = '/' . $path;
}

$this->path = rtrim($path, '/');
}

/**
Expand Down
15 changes: 12 additions & 3 deletions test/src/ride/library/router/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

class RouteTest extends PHPUnit_Framework_TestCase {

public function testConstruct() {
$path = 'path';
/**
* @dataProvider providerConstruct
*/
public function testConstruct($expectedPath, $path) {
$callback = 'callback';

$route = new Route($path, $callback);

$this->assertEquals('/' . $path, $route->getPath());
$this->assertEquals($route->getPath(), $expectedPath);
$this->assertEquals($callback, $route->getCallback());
$this->assertNull($route->getId());
$this->assertNull($route->getAllowedMethods());
Expand All @@ -31,6 +33,13 @@ public function testConstruct() {
$this->assertEquals(array($allowedMethod => true), $route->getAllowedMethods());
}

public function providerConstruct() {
return array(
array('/path', 'path'),
array('///admin', '///admin'),
);
}

/**
* @dataProvider providerSetPathThrowsExceptionWhenThePathIsInvalid
* @expectedException ride\library\router\exception\RouterException
Expand Down

0 comments on commit b5acf42

Please sign in to comment.