Skip to content

Commit

Permalink
Remove dev dependency on league/uri
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Nov 5, 2019
1 parent ca64f11 commit 532280d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sudo: false
language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
"cash/lrucache": "^1"
},
"require-dev": {
"php": ">=7.2",
"amphp/http-server-router": "^1",
"amphp/phpunit-util": "^1.1",
"amphp/php-cs-fixer-config": "dev-master",
"league/uri": "^6",
"phpunit/phpunit": "^8 || ^7",
"danielmiessler/sec-lists": "2019.3"
},
Expand Down
39 changes: 24 additions & 15 deletions test/DocumentRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Amp\Loop;
use Amp\Promise;
use Amp\Socket;
use League\Uri;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface as PsrUri;
use Psr\Log\LoggerInterface as PsrLogger;

class DocumentRootTest extends TestCase
Expand All @@ -23,7 +23,7 @@ class DocumentRootTest extends TestCase

private static function fixturePath(): string
{
return \sys_get_temp_dir() . "/aerys_root_test_fixture";
return \sys_get_temp_dir() . "/amp_http_static_content_test_fixture";
}

/**
Expand Down Expand Up @@ -92,6 +92,15 @@ public function createServer(Options $options = null): Server
return $server;
}

public function createUri(string $path): PsrUri
{
$uri = $this->createMock(PsrUri::class);
$uri->method('getPath')
->willReturn($path);

return $uri;
}

/**
* @dataProvider provideBadDocRoots
*/
Expand Down Expand Up @@ -125,7 +134,7 @@ public function testBasicFileResponse(): DocumentRoot
["/index.htm", "test"],
["/dir/../dir//..//././index.htm", "test"],
] as list($path, $contents)) {
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString($path));
$request = new Request($this->createMock(Client::class), "GET", $this->createUri($path));

$promise = $root->handleRequest($request);
/** @var \Amp\Http\Server\Response $response */
Expand All @@ -146,7 +155,7 @@ public function testBasicFileResponse(): DocumentRoot
*/
public function testPathsOnRelativePathAboveRoot(string $relativePath, DocumentRoot $root): void
{
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString($relativePath));
$request = new Request($this->createMock(Client::class), "GET", $this->createUri($relativePath));

$promise = $root->handleRequest($request);
/** @var \Amp\Http\Server\Response $response */
Expand All @@ -169,7 +178,7 @@ public function provideRelativePathsAboveRoot(): array
*/
public function testUnavailablePathsOnRelativePathAboveRoot(string $relativePath, DocumentRoot $root): void
{
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString($relativePath));
$request = new Request($this->createMock(Client::class), "GET", $this->createUri($relativePath));

$promise = $root->handleRequest($request);
/** @var \Amp\Http\Server\Response $response */
Expand All @@ -190,7 +199,7 @@ public function provideUnavailablePathsAboveRoot()
*/
public function testCachedResponse(DocumentRoot $root): void
{
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"));
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"));

$promise = $root->handleRequest($request);
/** @var \Amp\Http\Server\Response $response */
Expand All @@ -210,7 +219,7 @@ public function testDebugModeIgnoresCacheIfCacheControlHeaderIndicatesToDoSo(Doc

$root->onStart($server);

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"cache-control" => "no-cache",
]);

Expand All @@ -230,7 +239,7 @@ public function testDebugModeIgnoresCacheIfCacheControlHeaderIndicatesToDoSo(Doc
*/
public function testDebugModeIgnoresCacheIfPragmaHeaderIndicatesToDoSo(DocumentRoot $root): DocumentRoot
{
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"cache-control" => "no-cache",
]);

Expand All @@ -248,7 +257,7 @@ public function testDebugModeIgnoresCacheIfPragmaHeaderIndicatesToDoSo(DocumentR
public function testOptionsHeader(): void
{
$root = new DocumentRoot(self::fixturePath());
$request = new Request($this->createMock(Client::class), "OPTIONS", Uri\Http::createFromString("/"));
$request = new Request($this->createMock(Client::class), "OPTIONS", $this->createUri("/"));

$promise = $root->handleRequest($request);
/** @var \Amp\Http\Server\Response $response */
Expand All @@ -269,7 +278,7 @@ public function testPreconditionFailure(): void

$diskPath = \realpath(self::fixturePath())."/index.htm";

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"if-match" => "any value",
]);

Expand All @@ -287,7 +296,7 @@ public function testPreconditionNotModified(): void
$diskPath = \realpath(self::fixturePath())."/index.htm";
$etag = \md5($diskPath.\filemtime($diskPath).\filesize($diskPath));

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"if-match" => $etag,
"if-modified-since" => "2.1.1970",
]);
Expand All @@ -308,7 +317,7 @@ public function testPreconditionRangeFail(): void
$diskPath = \realpath(self::fixturePath())."/index.htm";
$etag = \md5($diskPath.\filemtime($diskPath).\filesize($diskPath));

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"if-range" => "foo",
]);

Expand All @@ -332,7 +341,7 @@ public function testBadRange(): void
$diskPath = \realpath(self::fixturePath())."/index.htm";
$etag = \md5($diskPath.\filemtime($diskPath).\filesize($diskPath));

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"if-range" => $etag,
"range" => "bytes=7-10",
]);
Expand All @@ -354,7 +363,7 @@ public function testValidRange(string $range, callable $validator): void
$root = new DocumentRoot(self::fixturePath());
$root->setUseEtagInode(false);

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/index.htm"), [
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/index.htm"), [
"if-range" => "+1 second",
"range" => "bytes=$range",
]);
Expand Down Expand Up @@ -409,7 +418,7 @@ public function provideValidRanges(): array
*/
public function testMimetypeParsing(DocumentRoot $root): void
{
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/svg.svg"));
$request = new Request($this->createMock(Client::class), "GET", $this->createUri("/svg.svg"));

$promise = $root->handleRequest($request);
/** @var \Amp\Http\Server\Response $response */
Expand Down

0 comments on commit 532280d

Please sign in to comment.