Test cleanup

This commit is contained in:
PJ Dietz 2017-08-03 14:29:54 -04:00
parent 3a77d99e00
commit 50f1004be5
11 changed files with 52 additions and 54 deletions

View File

@ -2,6 +2,6 @@
namespace WellRESTed\Test; namespace WellRESTed\Test;
class TestCase extends \PHPUnit\Framework\TestCase abstract class TestCase extends \PHPUnit\Framework\TestCase
{ {
} }

View File

@ -64,9 +64,6 @@ class DispatcherTest extends TestCase
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
/**
* @uses WellRESTed\Dispatching\DispatchStack
*/
public function testDispatchesArrayAsDispatchStack() public function testDispatchesArrayAsDispatchStack()
{ {
$middleware = new DispatcherTest_Middleware(); $middleware = new DispatcherTest_Middleware();

View File

@ -15,38 +15,38 @@ class NullStreamTest extends TestCase
public function testCloseDoesNothing() public function testCloseDoesNothing()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$stream->close(); $stream->close();
$this->assertTrue(true); // Asserting no exception occured. $this->assertTrue(true); // Asserting no exception occurred.
} }
public function testDetachReturnsNull() public function testDetachReturnsNull()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertNull($stream->detach()); $this->assertNull($stream->detach());
} }
public function testSizeReturnsZero() public function testSizeReturnsZero()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertEquals(0, $stream->getSize()); $this->assertEquals(0, $stream->getSize());
} }
public function testTellReturnsZero() public function testTellReturnsZero()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertEquals(0, $stream->tell()); $this->assertEquals(0, $stream->tell());
} }
public function testEofReturnsTrue() public function testEofReturnsTrue()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertTrue($stream->eof()); $this->assertTrue($stream->eof());
} }
public function testIsSeekableReturnsFalse() public function testIsSeekableReturnsFalse()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertFalse($stream->isSeekable()); $this->assertFalse($stream->isSeekable());
} }
@ -60,7 +60,7 @@ class NullStreamTest extends TestCase
/** @expectedException \RuntimeException */ /** @expectedException \RuntimeException */
public function testRewindThrowsException() public function testRewindThrowsException()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$stream->rewind(); $stream->rewind();
} }
@ -73,19 +73,19 @@ class NullStreamTest extends TestCase
/** @expectedException \RuntimeException */ /** @expectedException \RuntimeException */
public function testWriteThrowsException() public function testWriteThrowsException()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$stream->write(""); $stream->write("");
} }
public function testIsReadableReturnsTrue() public function testIsReadableReturnsTrue()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertTrue($stream->isReadable()); $this->assertTrue($stream->isReadable());
} }
public function testReadReturnsEmptyString() public function testReadReturnsEmptyString()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertEquals("", $stream->read(100)); $this->assertEquals("", $stream->read(100));
} }
@ -97,13 +97,13 @@ class NullStreamTest extends TestCase
public function testGetMetadataReturnsNull() public function testGetMetadataReturnsNull()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertNull($stream->getMetadata()); $this->assertNull($stream->getMetadata());
} }
public function testGetMetadataReturnsNullWithKey() public function testGetMetadataReturnsNullWithKey()
{ {
$stream = new \WellRESTed\Message\NullStream(); $stream = new NullStream();
$this->assertNull($stream->getMetadata("size")); $this->assertNull($stream->getMetadata("size"));
} }
} }

View File

@ -67,14 +67,14 @@ class ServerRequestTest extends TestCase
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @dataProvider methodProvider * @dataProvider methodProvider
*/ */
public function testGetServerRequestReadsMethod($exectedMethod, $serverMethod) public function testGetServerRequestReadsMethod($expectedMethod, $serverMethod)
{ {
$_SERVER = [ $_SERVER = [
"HTTP_HOST" => "localhost", "HTTP_HOST" => "localhost",
"REQUEST_METHOD" => $serverMethod "REQUEST_METHOD" => $serverMethod
]; ];
$request = ServerRequest::getServerRequest(); $request = ServerRequest::getServerRequest();
$this->assertEquals($exectedMethod, $request->getMethod()); $this->assertEquals($expectedMethod, $request->getMethod());
} }
public function methodProvider() public function methodProvider()
@ -93,14 +93,14 @@ class ServerRequestTest extends TestCase
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @dataProvider requestTargetProvider * @dataProvider requestTargetProvider
*/ */
public function testGetServerRequestReadsRequestTargetFromRequest($exectedRequestTarget, $serverRequestUri) public function testGetServerRequestReadsRequestTargetFromRequest($expectedRequestTarget, $serverRequestUri)
{ {
$_SERVER = [ $_SERVER = [
"HTTP_HOST" => "localhost", "HTTP_HOST" => "localhost",
"REQUEST_URI" => $serverRequestUri "REQUEST_URI" => $serverRequestUri
]; ];
$request = ServerRequest::getServerRequest(); $request = ServerRequest::getServerRequest();
$this->assertEquals($exectedRequestTarget, $request->getRequestTarget()); $this->assertEquals($expectedRequestTarget, $request->getRequestTarget());
} }
public function requestTargetProvider() public function requestTargetProvider()

View File

@ -25,13 +25,13 @@ class StreamTest extends TestCase
public function testCreatesInstanceWithStreamResource() public function testCreatesInstanceWithStreamResource()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$this->assertNotNull($stream); $this->assertNotNull($stream);
} }
public function testCreatesInstanceWithString() public function testCreatesInstanceWithString()
{ {
$stream = new \WellRESTed\Message\Stream("Hello, world!"); $stream = new Stream("Hello, world!");
$this->assertNotNull($stream); $this->assertNotNull($stream);
} }
@ -39,9 +39,9 @@ class StreamTest extends TestCase
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
* @dataProvider invalidResourceProvider * @dataProvider invalidResourceProvider
*/ */
public function testThrowsExceptiondWithInvalidResource($resource) public function testThrowsExceptionWithInvalidResource($resource)
{ {
new \WellRESTed\Message\Stream($resource); new Stream($resource);
} }
public function invalidResourceProvider() public function invalidResourceProvider()
@ -56,7 +56,7 @@ class StreamTest extends TestCase
public function testCastsToString() public function testCastsToString()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$this->assertEquals($this->content, (string) $stream); $this->assertEquals($this->content, (string) $stream);
} }
@ -75,20 +75,20 @@ class StreamTest extends TestCase
public function testDetachUnsetsInstanceVariable() public function testDetachUnsetsInstanceVariable()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$stream->detach(); $stream->detach();
$this->assertNull($stream->detach()); $this->assertNull($stream->detach());
} }
public function testReturnsSize() public function testReturnsSize()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$this->assertEquals(strlen($this->content), $stream->getSize()); $this->assertEquals(strlen($this->content), $stream->getSize());
} }
public function testTellReturnsHandlePosition() public function testTellReturnsHandlePosition()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
fseek($this->resource, 10); fseek($this->resource, 10);
$this->assertEquals(10, $stream->tell()); $this->assertEquals(10, $stream->tell());
} }
@ -103,7 +103,7 @@ class StreamTest extends TestCase
public function testReadsSeekableStatusFromMetadata() public function testReadsSeekableStatusFromMetadata()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$metadata = stream_get_meta_data($this->resource); $metadata = stream_get_meta_data($this->resource);
$seekable = $metadata["seekable"] == 1; $seekable = $metadata["seekable"] == 1;
$this->assertEquals($seekable, $stream->isSeekable()); $this->assertEquals($seekable, $stream->isSeekable());
@ -111,7 +111,7 @@ class StreamTest extends TestCase
public function testSeeksToPosition() public function testSeeksToPosition()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$stream->seek(10); $stream->seek(10);
$this->assertEquals(10, ftell($this->resource)); $this->assertEquals(10, ftell($this->resource));
} }
@ -127,7 +127,7 @@ class StreamTest extends TestCase
public function testWritesToHandle() public function testWritesToHandle()
{ {
$message = "\nThis is a stream."; $message = "\nThis is a stream.";
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$stream->write($message); $stream->write($message);
$this->assertEquals($this->content . $message, (string) $stream); $this->assertEquals($this->content . $message, (string) $stream);
} }
@ -137,7 +137,7 @@ class StreamTest extends TestCase
{ {
$filename = tempnam(sys_get_temp_dir(), "php"); $filename = tempnam(sys_get_temp_dir(), "php");
$handle = fopen($filename, "r"); $handle = fopen($filename, "r");
$stream = new \WellRESTed\Message\Stream($handle); $stream = new Stream($handle);
$stream->write("Hello, world!"); $stream->write("Hello, world!");
} }
@ -146,13 +146,13 @@ class StreamTest extends TestCase
{ {
$filename = tempnam(sys_get_temp_dir(), "php"); $filename = tempnam(sys_get_temp_dir(), "php");
$handle = fopen($filename, "w"); $handle = fopen($filename, "w");
$stream = new \WellRESTed\Message\Stream($handle); $stream = new Stream($handle);
$stream->read(10); $stream->read(10);
} }
public function testReadsFromStream() public function testReadsFromStream()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$stream->seek(7); $stream->seek(7);
$string = $stream->read(5); $string = $stream->read(5);
$this->assertEquals("world", $string); $this->assertEquals("world", $string);
@ -163,7 +163,7 @@ class StreamTest extends TestCase
{ {
$filename = tempnam(sys_get_temp_dir(), "php"); $filename = tempnam(sys_get_temp_dir(), "php");
$handle = fopen($filename, "w"); $handle = fopen($filename, "w");
$stream = new \WellRESTed\Message\Stream($handle); $stream = new Stream($handle);
$stream->getContents(); $stream->getContents();
} }
@ -177,7 +177,7 @@ class StreamTest extends TestCase
public function testReturnsMetadataArray() public function testReturnsMetadataArray()
{ {
$stream = new \WellRESTed\Message\Stream($this->resource); $stream = new Stream($this->resource);
$this->assertEquals(stream_get_meta_data($this->resource), $stream->getMetadata()); $this->assertEquals(stream_get_meta_data($this->resource), $stream->getMetadata());
} }
@ -189,7 +189,7 @@ class StreamTest extends TestCase
} }
/** @dataProvider modeProvider */ /** @dataProvider modeProvider */
public function testReturnsIsReadableForReadableStreams($mode, $readable, $writeable) public function testReturnsIsReadableForReadableStreams($mode, $readable, $writable)
{ {
$tmp = tempnam(sys_get_temp_dir(), "php"); $tmp = tempnam(sys_get_temp_dir(), "php");
if ($mode[0] === "x") { if ($mode[0] === "x") {
@ -201,15 +201,15 @@ class StreamTest extends TestCase
} }
/** @dataProvider modeProvider */ /** @dataProvider modeProvider */
public function testReturnsIsWritableForWritableStreams($mode, $readable, $writeable) public function testReturnsIsWritableForWritableStreams($mode, $readable, $writable)
{ {
$tmp = tempnam(sys_get_temp_dir(), "php"); $tmp = tempnam(sys_get_temp_dir(), "php");
if ($mode[0] === "x") { if ($mode[0] === "x") {
unlink($tmp); unlink($tmp);
} }
$resource = fopen($tmp, $mode); $resource = fopen($tmp, $mode);
$stream = new \WellRESTed\Message\Stream($resource); $stream = new Stream($resource);
$this->assertEquals($writeable, $stream->isWritable()); $this->assertEquals($writable, $stream->isWritable());
} }
public function modeProvider() public function modeProvider()

View File

@ -79,7 +79,7 @@ class UploadedFileTest extends TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// moveTo // moveTo
public function testMoveToSapiRelocatesUploadedFileToDestiationIfExists() public function testMoveToSapiRelocatesUploadedFileToDestinationIfExists()
{ {
UploadedFileState::$php_sapi_name = "fpm-fcgi"; UploadedFileState::$php_sapi_name = "fpm-fcgi";
@ -93,7 +93,7 @@ class UploadedFileTest extends TestCase
$this->assertEquals($originalMd5, md5_file($this->movePath)); $this->assertEquals($originalMd5, md5_file($this->movePath));
} }
public function testMoveToNonSapiRelocatesUploadedFileToDestiationIfExists() public function testMoveToNonSapiRelocatesUploadedFileToDestinationIfExists()
{ {
$content = "Hello, World!"; $content = "Hello, World!";
file_put_contents($this->tmpName, $content); file_put_contents($this->tmpName, $content);

View File

@ -364,7 +364,7 @@ class UriTest extends TestCase
{ {
$uri = new Uri(); $uri = new Uri();
$uri = $uri->withQuery($query); $uri = $uri->withQuery($query);
$uri = $uri->withQuery($uri->getQuery($query)); $uri = $uri->withQuery($uri->getQuery());
$this->assertSame($expected, $uri->getQuery()); $this->assertSame($expected, $uri->getQuery());
} }
@ -418,7 +418,7 @@ class UriTest extends TestCase
{ {
$uri = new Uri(); $uri = new Uri();
$uri = $uri->withFragment($fragment); $uri = $uri->withFragment($fragment);
$uri = $uri->withFragment($uri->getFragment($fragment)); $uri = $uri->withFragment($uri->getFragment());
$this->assertSame($expected, $uri->getFragment()); $this->assertSame($expected, $uri->getFragment());
} }

View File

@ -95,7 +95,7 @@ class MethodMapTest extends TestCase
$this->assertEquals(2, $this->middleware->callCount); $this->assertEquals(2, $this->middleware->callCount);
} }
public function testSettingNullUnregistersMiddleware() public function testSettingNullDeregistersMiddleware()
{ {
$this->request = $this->request->withMethod("POST"); $this->request = $this->request->withMethod("POST");

View File

@ -2,7 +2,8 @@
namespace WellRESTed\Test\Unit\Routing\Route; namespace WellRESTed\Test\Unit\Routing\Route;
use PHPUnit\Framework\Error\Error; use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\Error\Warning;
use WellRESTed\Routing\Route\RegexRoute; use WellRESTed\Routing\Route\RegexRoute;
use WellRESTed\Routing\Route\RouteInterface; use WellRESTed\Routing\Route\RouteInterface;
use WellRESTed\Test\TestCase; use WellRESTed\Test\TestCase;
@ -84,14 +85,14 @@ class RegexRouteTest extends TestCase
public function testThrowsExceptionOnInvalidPattern($pattern) public function testThrowsExceptionOnInvalidPattern($pattern)
{ {
$route = new RegexRoute($pattern, $this->methodMap->reveal()); $route = new RegexRoute($pattern, $this->methodMap->reveal());
\PHPUnit\Framework\Error\Warning::$enabled = false; Warning::$enabled = false;
\PHPUnit\Framework\Error\Notice::$enabled = false; Notice::$enabled = false;
$level = error_reporting(); $level = error_reporting();
error_reporting($level & ~E_WARNING); error_reporting($level & ~E_WARNING);
$route->matchesRequestTarget("/"); $route->matchesRequestTarget("/");
error_reporting($level); error_reporting($level);
\PHPUnit\Framework\Error\Warning::$enabled = true; Warning::$enabled = true;
\PHPUnit\Framework\Error\Notice::$enabled = true; Notice::$enabled = true;
} }
public function invalidRouteProvider() public function invalidRouteProvider()

View File

@ -62,8 +62,8 @@ class TemplateRouteTest extends TestCase
return [ return [
["/foo/{var}", "/bar/12", "Mismatch before first template expression"], ["/foo/{var}", "/bar/12", "Mismatch before first template expression"],
["/foo/{foo}/bar/{bar}", "/foo/12/13", "Mismatch after first template expression"], ["/foo/{foo}/bar/{bar}", "/foo/12/13", "Mismatch after first template expression"],
["/hello/{hello}", "/hello/Hello%20World!", "Requires + operator to match reserver characters"], ["/hello/{hello}", "/hello/Hello%20World!", "Requires + operator to match reserved characters"],
["{/var}", "/bar/12", "Path contains more segements than template"], ["{/var}", "/bar/12", "Path contains more segments than template"],
]; ];
} }

View File

@ -178,7 +178,7 @@ class TransmitterTest extends TestCase
$this->assertContains("Content-length: $bodySize", HeaderStack::getHeaders()); $this->assertContains("Content-length: $bodySize", HeaderStack::getHeaders());
} }
public function testDoesNotReplaceContentLengthHeaderWhenContentLenghtIsAlreadySet() public function testDoesNotReplaceContentLengthHeaderWhenContentLengthIsAlreadySet()
{ {
$streamSize = 1024; $streamSize = 1024;
$headerSize = 2048; $headerSize = 2048;