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\StreamInterface;
use WellRESTed\Stream\NullStream;
abstract class Message implements MessageInterface
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
<?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
{
@ -26,28 +26,28 @@ class StreamTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers WellRESTed\Stream\Stream::__construct()
* @covers WellRESTed\Message\Stream::__construct()
*/
public function testCreatesInstanceWithStreamResource()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertNotNull($stream);
}
public function testCreatesInstanceWithString()
{
$stream = new Stream("Hello, world!");
$stream = new \WellRESTed\Message\Stream("Hello, world!");
$this->assertNotNull($stream);
}
/**
* @covers WellRESTed\Stream\Stream::__construct()
* @covers WellRESTed\Message\Stream::__construct()
* @expectedException \InvalidArgumentException
* @dataProvider invalidResourceProvider
*/
public function testThrowsExceptiondWithInvalidResource($resource)
{
new Stream($resource);
new \WellRESTed\Message\Stream($resource);
}
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()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertEquals($this->content, (string) $stream);
}
/**
* @covers WellRESTed\Stream\Stream::close()
* @covers WellRESTed\Message\Stream::close()
*/
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()
{
@ -89,36 +89,36 @@ class StreamTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers WellRESTed\Stream\Stream::detach()
* @covers WellRESTed\Message\Stream::detach()
*/
public function testDetachUnsetsInstanceVariable()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$stream->detach();
$this->assertNull($stream->detach());
}
/**
* @covers WellRESTed\Stream\Stream::getSize
* @covers WellRESTed\Message\Stream::getSize
*/
public function testReturnsSize()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertEquals(strlen($this->content), $stream->getSize());
}
/**
* @covers WellRESTed\Stream\Stream::tell
* @covers WellRESTed\Message\Stream::tell
*/
public function testTellReturnsHandlePosition()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
fseek($this->resource, 10);
$this->assertEquals(10, $stream->tell());
}
/**
* @covers WellRESTed\Stream\Stream::eof
* @covers WellRESTed\Message\Stream::eof
*/
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()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$metadata = stream_get_meta_data($this->resource);
$seekable = $metadata["seekable"] == 1;
$this->assertEquals($seekable, $stream->isSeekable());
}
/**
* @covers WellRESTed\Stream\Stream::seek
* @covers WellRESTed\Message\Stream::seek
*/
public function testSeeksToPosition()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$stream->seek(10);
$this->assertEquals(10, ftell($this->resource));
}
/**
* @covers WellRESTed\Stream\Stream::rewind
* @covers WellRESTed\Message\Stream::rewind
*/
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()
{
$message = "\nThis is a stream.";
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$stream->write($message);
$this->assertEquals($this->content . $message, (string) $stream);
}
/**
* @covers WellRESTed\Stream\Stream::read
* @covers WellRESTed\Message\Stream::read
*/
public function testReadsFromStream()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$stream->seek(7);
$string = $stream->read(5);
$this->assertEquals("world", $string);
}
/**
* @covers WellRESTed\Stream\Stream::getContents
* @covers WellRESTed\Message\Stream::getContents
*/
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()
{
$stream = new Stream($this->resource);
$stream = new \WellRESTed\Message\Stream($this->resource);
$this->assertEquals(stream_get_meta_data($this->resource), $stream->getMetadata());
}
/**
* @covers WellRESTed\Stream\Stream::getMetadata
* @covers WellRESTed\Message\Stream::getMetadata
*/
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
*/
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
*/
public function testReturnsIsWritableForWritableStreams($mode, $readable, $writeable)
@ -239,7 +239,7 @@ class StreamTest extends \PHPUnit_Framework_TestCase
unlink($tmp);
}
$resource = fopen($tmp, $mode);
$stream = new Stream($resource);
$stream = new \WellRESTed\Message\Stream($resource);
$this->assertEquals($writeable, $stream->isWritable());
}

View File

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