Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  Use mb_convert_encoding instead of utf8_decode
  [FrameworkBundle] Always add CacheCollectorPass
  Fix "Notice: Undefined index: headers" in messenger with Oracle
  [String] Fix ansi escape sequences regex
  Indicate support for doctrine/persistence 3
  [Routing] fix router base url when default uri has trailing slash
  Replace deprecated String.prototype.substr()
  • Loading branch information
derrabus committed Apr 22, 2022
2 parents 0cf480c + e07817b commit 74c40c9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getBaseUrl(): string
*/
public function setBaseUrl(string $baseUrl): static
{
$this->baseUrl = $baseUrl;
$this->baseUrl = rtrim($baseUrl, '/');

return $this;
}
Expand Down
45 changes: 45 additions & 0 deletions Tests/RequestContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,51 @@ public function testConstruct()
$this->assertEquals('bar=foobar', $requestContext->getQueryString());
}

public function testFromUriWithBaseUrl()
{
$requestContext = RequestContext::fromUri('https://test.com:444/index.php');

$this->assertSame('GET', $requestContext->getMethod());
$this->assertSame('https', $requestContext->getScheme());
$this->assertSame('test.com', $requestContext->getHost());
$this->assertSame('/index.php', $requestContext->getBaseUrl());
$this->assertSame('/', $requestContext->getPathInfo());
$this->assertSame(80, $requestContext->getHttpPort());
$this->assertSame(444, $requestContext->getHttpsPort());
}

public function testFromUriWithTrailingSlash()
{
$requestContext = RequestContext::fromUri('http://test.com:8080/');

$this->assertSame('http', $requestContext->getScheme());
$this->assertSame('test.com', $requestContext->getHost());
$this->assertSame(8080, $requestContext->getHttpPort());
$this->assertSame(443, $requestContext->getHttpsPort());
$this->assertSame('', $requestContext->getBaseUrl());
$this->assertSame('/', $requestContext->getPathInfo());
}

public function testFromUriWithoutTrailingSlash()
{
$requestContext = RequestContext::fromUri('https://test.com');

$this->assertSame('https', $requestContext->getScheme());
$this->assertSame('test.com', $requestContext->getHost());
$this->assertSame('', $requestContext->getBaseUrl());
$this->assertSame('/', $requestContext->getPathInfo());
}

public function testFromUriBeingEmpty()
{
$requestContext = RequestContext::fromUri('');

$this->assertSame('http', $requestContext->getScheme());
$this->assertSame('localhost', $requestContext->getHost());
$this->assertSame('', $requestContext->getBaseUrl());
$this->assertSame('/', $requestContext->getPathInfo());
}

public function testFromRequest()
{
$request = Request::create('https://test.com:444/foo?bar=baz');
Expand Down

0 comments on commit 74c40c9

Please sign in to comment.