Move Stream classes into Message namespace

This commit is contained in:
PJ Dietz 2015-04-15 19:39:53 -04:00
parent 6b20d1ea96
commit 408d82fb73
10 changed files with 73 additions and 75 deletions

View File

@ -4,7 +4,6 @@ namespace WellRESTed\Message;
use Psr\Http\Message\MessageInterface; use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;
use WellRESTed\Stream\NullStream;
abstract class Message implements MessageInterface abstract class Message implements MessageInterface
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace WellRESTed\Stream; namespace WellRESTed\Message;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;

View File

@ -5,7 +5,6 @@ namespace WellRESTed\Message;
use Psr\Http\Message\An; use Psr\Http\Message\An;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;
use WellRESTed\Stream\Stream;
class ServerRequest extends Request implements ServerRequestInterface class ServerRequest extends Request implements ServerRequestInterface
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace WellRESTed\Stream; namespace WellRESTed\Message;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;

View File

@ -7,9 +7,9 @@ use Psr\Http\Message\ServerRequestInterface;
use WellRESTed\HttpExceptions\HttpException; use WellRESTed\HttpExceptions\HttpException;
use WellRESTed\Message\Response; use WellRESTed\Message\Response;
use WellRESTed\Message\ServerRequest; use WellRESTed\Message\ServerRequest;
use WellRESTed\Message\Stream;
use WellRESTed\Routing\Route\RouteFactory; use WellRESTed\Routing\Route\RouteFactory;
use WellRESTed\Routing\Route\RouteFactoryInterface; use WellRESTed\Routing\Route\RouteFactoryInterface;
use WellRESTed\Stream\Stream;
class Router implements MiddlewareInterface class Router implements MiddlewareInterface
{ {

View File

@ -224,7 +224,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
/** /**
* @covers WellRESTed\Message\Message::getBody * @covers WellRESTed\Message\Message::getBody
* @uses WellRESTed\Stream\NullStream * @uses WellRESTed\Message\NullStream
*/ */
public function testGetBodyReturnsEmptyStreamByDefault() public function testGetBodyReturnsEmptyStreamByDefault()
{ {

View File

@ -1,13 +1,13 @@
<?php <?php
namespace WellRESTed\Test\Stream; namespace WellRESTed\Test\Message;
use WellRESTed\Stream\NullStream; use WellRESTed\Message\NullStream;
class NullStreamTest extends \PHPUnit_Framework_TestCase class NullStreamTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @covers WellRESTed\Stream\NullStream::__toString() * @covers WellRESTed\Message\NullStream::__toString()
*/ */
public function testCastsToString() public function testCastsToString()
{ {
@ -17,59 +17,59 @@ class NullStreamTest extends \PHPUnit_Framework_TestCase
public function testCloseDoesNothing() public function testCloseDoesNothing()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertNull($stream->close()); $this->assertNull($stream->close());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::detach() * @covers WellRESTed\Message\NullStream::detach()
* @uses WellRESTed\Stream\Stream * @uses WellRESTed\Message\Stream
*/ */
public function testDetachReturnsNull() public function testDetachReturnsNull()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertNull($stream->detach()); $this->assertNull($stream->detach());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::getSize * @covers WellRESTed\Message\NullStream::getSize
* @uses WellRESTed\Stream\Stream * @uses WellRESTed\Message\Stream
*/ */
public function testSizeReturnsZero() public function testSizeReturnsZero()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertEquals(0, $stream->getSize()); $this->assertEquals(0, $stream->getSize());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::tell * @covers WellRESTed\Message\NullStream::tell
*/ */
public function testTellReturnsFalse() public function testTellReturnsFalse()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertFalse($stream->tell()); $this->assertFalse($stream->tell());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::eof * @covers WellRESTed\Message\NullStream::eof
*/ */
public function testEofReturnsReturnsTrue() public function testEofReturnsReturnsTrue()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertTrue($stream->eof()); $this->assertTrue($stream->eof());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::isSeekable * @covers WellRESTed\Message\NullStream::isSeekable
* @uses WellRESTed\Stream\Stream * @uses WellRESTed\Message\Stream
*/ */
public function testIsSeekableReturnsFalse() public function testIsSeekableReturnsFalse()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertFalse($stream->isSeekable()); $this->assertFalse($stream->isSeekable());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::seek * @covers WellRESTed\Message\NullStream::seek
*/ */
public function testSeekReturnsFalse() public function testSeekReturnsFalse()
{ {
@ -78,16 +78,16 @@ class NullStreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\NullStream::rewind * @covers WellRESTed\Message\NullStream::rewind
*/ */
public function testRewindReturnsFalse() public function testRewindReturnsFalse()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertFalse($stream->rewind()); $this->assertFalse($stream->rewind());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::isWritable * @covers WellRESTed\Message\NullStream::isWritable
*/ */
public function testIsWritableReturnsFalse() public function testIsWritableReturnsFalse()
{ {
@ -96,34 +96,34 @@ class NullStreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\NullStream::write * @covers WellRESTed\Message\NullStream::write
*/ */
public function testWriteReturnsFalse() public function testWriteReturnsFalse()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertFalse($stream->write("")); $this->assertFalse($stream->write(""));
} }
/** /**
* @covers WellRESTed\Stream\NullStream::isReadable * @covers WellRESTed\Message\NullStream::isReadable
*/ */
public function testIsReableReturnsTrue() public function testIsReableReturnsTrue()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertTrue($stream->isReadable()); $this->assertTrue($stream->isReadable());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::read * @covers WellRESTed\Message\NullStream::read
*/ */
public function testReadReturnsEmptyString() public function testReadReturnsEmptyString()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertEquals("", $stream->read(100)); $this->assertEquals("", $stream->read(100));
} }
/** /**
* @covers WellRESTed\Stream\NullStream::getContents * @covers WellRESTed\Message\NullStream::getContents
*/ */
public function testGetContentsReturnsEmptyString() public function testGetContentsReturnsEmptyString()
{ {
@ -132,20 +132,20 @@ class NullStreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\NullStream::getMetadata * @covers WellRESTed\Message\NullStream::getMetadata
*/ */
public function testGetMetadataReturnsNull() public function testGetMetadataReturnsNull()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertNull($stream->getMetadata()); $this->assertNull($stream->getMetadata());
} }
/** /**
* @covers WellRESTed\Stream\NullStream::getMetadata * @covers WellRESTed\Message\NullStream::getMetadata
*/ */
public function testGetMetadataReturnsNullWithKey() public function testGetMetadataReturnsNullWithKey()
{ {
$stream = new NullStream(); $stream = new \WellRESTed\Message\NullStream();
$this->assertNull($stream->getMetadata("size")); $this->assertNull($stream->getMetadata("size"));
} }
} }

View File

@ -9,7 +9,7 @@ use WellRESTed\Message\ServerRequest;
* @uses WellRESTed\Message\Request * @uses WellRESTed\Message\Request
* @uses WellRESTed\Message\Message * @uses WellRESTed\Message\Message
* @uses WellRESTed\Message\HeaderCollection * @uses WellRESTed\Message\HeaderCollection
* @uses WellRESTed\Stream\Stream * @uses WellRESTed\Message\Stream
*/ */
class ServerRequestTest extends \PHPUnit_Framework_TestCase class ServerRequestTest extends \PHPUnit_Framework_TestCase
{ {

View File

@ -1,11 +1,11 @@
<?php <?php
namespace WellRESTed\Test\Stream; namespace WellRESTed\Test\Message;
use WellRESTed\Stream\Stream; use WellRESTed\Message\Stream;
/** /**
* @uses WellRESTed\Stream\Stream * @uses WellRESTed\Message\Stream
*/ */
class StreamTest extends \PHPUnit_Framework_TestCase class StreamTest extends \PHPUnit_Framework_TestCase
{ {
@ -26,28 +26,28 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::__construct() * @covers WellRESTed\Message\Stream::__construct()
*/ */
public function testCreatesInstanceWithStreamResource() public function testCreatesInstanceWithStreamResource()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertNotNull($stream); $this->assertNotNull($stream);
} }
public function testCreatesInstanceWithString() public function testCreatesInstanceWithString()
{ {
$stream = new Stream("Hello, world!"); $stream = new \WellRESTed\Message\Stream("Hello, world!");
$this->assertNotNull($stream); $this->assertNotNull($stream);
} }
/** /**
* @covers WellRESTed\Stream\Stream::__construct() * @covers WellRESTed\Message\Stream::__construct()
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
* @dataProvider invalidResourceProvider * @dataProvider invalidResourceProvider
*/ */
public function testThrowsExceptiondWithInvalidResource($resource) public function testThrowsExceptiondWithInvalidResource($resource)
{ {
new Stream($resource); new \WellRESTed\Message\Stream($resource);
} }
public function invalidResourceProvider() public function invalidResourceProvider()
@ -61,16 +61,16 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::__toString() * @covers WellRESTed\Message\Stream::__toString()
*/ */
public function testCastsToString() public function testCastsToString()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertEquals($this->content, (string) $stream); $this->assertEquals($this->content, (string) $stream);
} }
/** /**
* @covers WellRESTed\Stream\Stream::close() * @covers WellRESTed\Message\Stream::close()
*/ */
public function testClosesHandle() public function testClosesHandle()
{ {
@ -80,7 +80,7 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::detach() * @covers WellRESTed\Message\Stream::detach()
*/ */
public function testDetachReturnsHandle() public function testDetachReturnsHandle()
{ {
@ -89,36 +89,36 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::detach() * @covers WellRESTed\Message\Stream::detach()
*/ */
public function testDetachUnsetsInstanceVariable() public function testDetachUnsetsInstanceVariable()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$stream->detach(); $stream->detach();
$this->assertNull($stream->detach()); $this->assertNull($stream->detach());
} }
/** /**
* @covers WellRESTed\Stream\Stream::getSize * @covers WellRESTed\Message\Stream::getSize
*/ */
public function testReturnsSize() public function testReturnsSize()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertEquals(strlen($this->content), $stream->getSize()); $this->assertEquals(strlen($this->content), $stream->getSize());
} }
/** /**
* @covers WellRESTed\Stream\Stream::tell * @covers WellRESTed\Message\Stream::tell
*/ */
public function testTellReturnsHandlePosition() public function testTellReturnsHandlePosition()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
fseek($this->resource, 10); fseek($this->resource, 10);
$this->assertEquals(10, $stream->tell()); $this->assertEquals(10, $stream->tell());
} }
/** /**
* @covers WellRESTed\Stream\Stream::eof * @covers WellRESTed\Message\Stream::eof
*/ */
public function testReturnsOef() public function testReturnsOef()
{ {
@ -130,28 +130,28 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::isSeekable * @covers WellRESTed\Message\Stream::isSeekable
*/ */
public function testReadsSeekableStatusFromMetadata() public function testReadsSeekableStatusFromMetadata()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\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());
} }
/** /**
* @covers WellRESTed\Stream\Stream::seek * @covers WellRESTed\Message\Stream::seek
*/ */
public function testSeeksToPosition() public function testSeeksToPosition()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$stream->seek(10); $stream->seek(10);
$this->assertEquals(10, ftell($this->resource)); $this->assertEquals(10, ftell($this->resource));
} }
/** /**
* @covers WellRESTed\Stream\Stream::rewind * @covers WellRESTed\Message\Stream::rewind
*/ */
public function testRewindReturnsToBeginning() public function testRewindReturnsToBeginning()
{ {
@ -162,29 +162,29 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::write * @covers WellRESTed\Message\Stream::write
*/ */
public function testWritesToHandle() public function testWritesToHandle()
{ {
$message = "\nThis is a stream."; $message = "\nThis is a stream.";
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$stream->write($message); $stream->write($message);
$this->assertEquals($this->content . $message, (string) $stream); $this->assertEquals($this->content . $message, (string) $stream);
} }
/** /**
* @covers WellRESTed\Stream\Stream::read * @covers WellRESTed\Message\Stream::read
*/ */
public function testReadsFromStream() public function testReadsFromStream()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\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);
} }
/** /**
* @covers WellRESTed\Stream\Stream::getContents * @covers WellRESTed\Message\Stream::getContents
*/ */
public function testReadsToEnd() public function testReadsToEnd()
{ {
@ -195,16 +195,16 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::getMetadata * @covers WellRESTed\Message\Stream::getMetadata
*/ */
public function testReturnsMetadataArray() public function testReturnsMetadataArray()
{ {
$stream = new Stream($this->resource); $stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertEquals(stream_get_meta_data($this->resource), $stream->getMetadata()); $this->assertEquals(stream_get_meta_data($this->resource), $stream->getMetadata());
} }
/** /**
* @covers WellRESTed\Stream\Stream::getMetadata * @covers WellRESTed\Message\Stream::getMetadata
*/ */
public function testReturnsMetadataItem() public function testReturnsMetadataItem()
{ {
@ -214,7 +214,7 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::isReadable * @covers WellRESTed\Message\Stream::isReadable
* @dataProvider modeProvider * @dataProvider modeProvider
*/ */
public function testReturnsIsReadableForReadableStreams($mode, $readable, $writeable) public function testReturnsIsReadableForReadableStreams($mode, $readable, $writeable)
@ -229,7 +229,7 @@ class StreamTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers WellRESTed\Stream\Stream::isWritable * @covers WellRESTed\Message\Stream::isWritable
* @dataProvider modeProvider * @dataProvider modeProvider
*/ */
public function testReturnsIsWritableForWritableStreams($mode, $readable, $writeable) public function testReturnsIsWritableForWritableStreams($mode, $readable, $writeable)
@ -239,7 +239,7 @@ class StreamTest extends \PHPUnit_Framework_TestCase
unlink($tmp); unlink($tmp);
} }
$resource = fopen($tmp, $mode); $resource = fopen($tmp, $mode);
$stream = new Stream($resource); $stream = new \WellRESTed\Message\Stream($resource);
$this->assertEquals($writeable, $stream->isWritable()); $this->assertEquals($writeable, $stream->isWritable());
} }

View File

@ -17,7 +17,7 @@ use WellRESTed\Routing\Router;
* @uses WellRESTed\Routing\Route\PrefixRoute * @uses WellRESTed\Routing\Route\PrefixRoute
* @uses WellRESTed\Routing\Route\StaticRoute * @uses WellRESTed\Routing\Route\StaticRoute
* @uses WellRESTed\Routing\Route\Route * @uses WellRESTed\Routing\Route\Route
* @uses WellRESTed\Stream\Stream * @uses WellRESTed\Message\Stream
*/ */
class RouterTest extends \PHPUnit_Framework_TestCase class RouterTest extends \PHPUnit_Framework_TestCase
{ {