Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding RouteParser::getBasePath method (no changes to RouteParserInterface) #2859

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions Slim/Routing/RouteParser.php
Expand Up @@ -125,4 +125,14 @@ public function fullUrlFor(UriInterface $uri, string $routeName, array $data = [
$protocol = ($scheme ? $scheme . ':' : '') . ($authority ? '//' . $authority : '');
return $protocol . $path;
}

/**
* Get base path
*
* @return string
*/
public function getBasePath(): string
{
return $this->routeCollector->getBasePath();
}
}
13 changes: 13 additions & 0 deletions tests/Routing/RouteParserTest.php
Expand Up @@ -194,4 +194,17 @@ public function testFullUrlFor()
$expectedResult = 'http://example.com:8080/app/123';
$this->assertEquals($expectedResult, $result);
}

public function testGetBasePath()
{
$responseFactoryProphecy = $this->prophesize(ResponseFactoryInterface::class);
$callableResolverProphecy = $this->prophesize(CallableResolverInterface::class);

$routeCollector = new RouteCollector($responseFactoryProphecy->reveal(), $callableResolverProphecy->reveal());
$routeCollector->setBasePath('/app');

$routeParser = $routeCollector->getRouteParser();

$this->assertEquals('/app', $routeParser->getBasePath());
}
}