mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Fixed Route::setUrl() behavior
When there are no parameters in the url, correctly empty the routes parameter array
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Pecee\Http\Request;
|
||||
|
||||
class DummyLoadableRoute extends Pecee\SimpleRouter\Route\LoadableRoute {
|
||||
|
||||
public function matchRoute(string $url, Request $request): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
require_once 'Dummy/Route/DummyLoadableRoute.php';
|
||||
|
||||
class LoadableRouteTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testSetUrlUpdatesParameters()
|
||||
{
|
||||
$route = new DummyLoadableRoute();
|
||||
$this->assertEmpty($route->getParameters());
|
||||
|
||||
$route->setUrl('/');
|
||||
$this->assertEmpty($route->getParameters());
|
||||
|
||||
$expected = ['param' => null, 'optionalParam' => null];
|
||||
$route->setUrl('/{param}/{optionalParam?}');
|
||||
$this->assertEquals($expected, $route->getParameters());
|
||||
|
||||
$expected = ['otherParam' => null];
|
||||
$route->setUrl('/{otherParam}');
|
||||
$this->assertEquals($expected, $route->getParameters());
|
||||
|
||||
$expected = [];
|
||||
$route->setUrl('/');
|
||||
$this->assertEquals($expected, $route->getParameters());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user