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;
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());
}
/**
* @uses WellRESTed\Dispatching\DispatchStack
*/
public function testDispatchesArrayAsDispatchStack()
{
$middleware = new DispatcherTest_Middleware();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -62,8 +62,8 @@ class TemplateRouteTest extends TestCase
return [
["/foo/{var}", "/bar/12", "Mismatch before 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"],
["{/var}", "/bar/12", "Path contains more segements than template"],
["/hello/{hello}", "/hello/Hello%20World!", "Requires + operator to match reserved characters"],
["{/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());
}
public function testDoesNotReplaceContentLengthHeaderWhenContentLenghtIsAlreadySet()
public function testDoesNotReplaceContentLengthHeaderWhenContentLengthIsAlreadySet()
{
$streamSize = 1024;
$headerSize = 2048;