[BUGFIX] Fixed issue with child groups not loading when using partialGroups (issue: #456)

This commit is contained in:
Simon Sessingø
2021-03-21 07:39:17 +01:00
parent e78040aabd
commit d70b153189
4 changed files with 69 additions and 11 deletions
@@ -25,4 +25,49 @@ class RouterPartialGroupTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('param2', $result2);
}
/**
* Fixed issue with partial routes not loading child groups.
* Reported in issue: #456
*/
public function testPartialGroupWithGroup() {
$lang = null;
$route1 = '/lang/da/test/';
$route2 = '/lang/da/auth';
$route3 = '/lang/da/auth/test';
TestRouter::partialGroup(
'/lang/{test}/',
function ($lang = 'en') use($route1, $route2, $route3) {
TestRouter::get('/test/', function () use($route1) {
return $route1;
});
TestRouter::group(['prefix' => '/auth/'], function () use($route2, $route3) {
TestRouter::get('/', function() use($route2) {
return $route2;
});
TestRouter::get('/test', function () use($route3){
return $route3;
});
});
}
);
$test1 = TestRouter::debugOutput('/lang/da/test', 'get', false);
$test2 = TestRouter::debugOutput('/lang/da/auth', 'get', false);
$test3 = TestRouter::debugOutput('/lang/da/auth/test', 'get', false);
$this->assertEquals($test1, $route1);
$this->assertEquals($test2, $route2);
$this->assertEquals($test3, $route3);
}
}
+6 -4
View File
@@ -13,7 +13,7 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
static::start();
}
public static function debug($testUrl, $testMethod = 'get')
public static function debug($testUrl, $testMethod = 'get', bool $reset = true)
{
try {
static::debugNoReset($testUrl, $testMethod);
@@ -22,17 +22,19 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
throw $e;
}
static::router()->reset();
if($reset === true) {
static::router()->reset();
}
}
public static function debugOutput($testUrl, $testMethod = 'get')
public static function debugOutput($testUrl, $testMethod = 'get', bool $reset = true)
{
$response = null;
// Route request
ob_start();
static::debug($testUrl, $testMethod);
static::debug($testUrl, $testMethod, $reset);
$response = ob_get_contents();
ob_end_clean();