Refactor URI; fix coverage on UploadedFile

This commit is contained in:
PJ Dietz 2020-08-15 07:51:30 -04:00
parent c137a2066a
commit 36df1f33c1
4 changed files with 30 additions and 44 deletions

View File

@ -31,7 +31,8 @@
"autoload-dev": {
"psr-4": {
"WellRESTed\\": "test/tests/unit/",
"WellRESTed\\Test\\": "test/src/"
"WellRESTed\\Test\\": "test/src/",
"WellRESTed\\Test\\Integration\\": "test/tests/integration/"
}
}
}

View File

@ -18,25 +18,25 @@ use Psr\Http\Message\UriInterface;
*/
class Uri implements UriInterface
{
const MIN_PORT = 0;
const MAX_PORT = 65535;
private const MIN_PORT = 0;
private const MAX_PORT = 65535;
/** @var string */
private $scheme = '';
private $scheme;
/** @var string */
private $user;
/** @var string */
private $user = '';
/** @var string|null */
private $password;
/** @var string */
private $host = '';
private $host;
/** @var int|null */
private $port;
/** @var string */
private $path = '';
private $path;
/** @var string */
private $query = '';
private $query;
/** @var string */
private $fragment = '';
private $fragment;
/**
* @param string $uri A string representation of a URI.
@ -44,34 +44,15 @@ class Uri implements UriInterface
public function __construct(string $uri = '')
{
$parsed = parse_url($uri);
if (!$parsed) {
return;
}
if (isset($parsed['scheme'])) {
$this->scheme = $parsed['scheme'];
}
if (isset($parsed['host'])) {
$this->host = strtolower($parsed['host']);
}
if (isset($parsed['port'])) {
$this->port = $parsed['port'];
}
if (isset($parsed['user'])) {
$this->user = $parsed['user'];
}
if (isset($parsed['pass'])) {
$this->password = $parsed['pass'];
}
if (isset($parsed['path'])) {
$this->path = $parsed['path'];
}
if (isset($parsed['query'])) {
$this->query = $parsed['query'];
}
if (isset($parsed['fragment'])) {
$this->fragment = $parsed['fragment'];
}
$this->scheme = $parsed['scheme'] ?? '';
$this->user = $parsed['user'] ?? '';
$this->password = $parsed['pass'] ?? '';
$this->host = strtolower($parsed['host'] ?? '');
$this->port = $parsed['port'] ?? null;
$this->path = $parsed['path'] ?? '';
$this->query = $parsed['query'] ?? '';
$this->fragment = $parsed['fragment'] ?? '';
}
/**
@ -338,7 +319,7 @@ class Uri implements UriInterface
{
$uri = clone $this;
$uri->user = $user;
$uri->password = $password;
$uri->password = $password ?? '';
return $uri;
}

View File

@ -70,7 +70,7 @@ class UploadedFileTest extends TestCase
$this->expectException(RuntimeException::class);
UploadedFileState::$php_sapi_name = 'apache';
UploadedFileState::$is_uploaded_file = false;
$file = new UploadedFile('', '', 0, '', 0);
$file = new UploadedFile('', '', 0, $this->tmpName, 0);
$file->getStream();
}

View File

@ -16,7 +16,11 @@ class UriTest extends TestCase
$this->assertSame('', $uri->getScheme());
}
/** @dataProvider schemeProvider */
/**
* @dataProvider schemeProvider
* @param $expected
* @param $scheme
*/
public function testSetsSchemeCaseInsensitively($expected, $scheme): void
{
$uri = new Uri();