Add StringStream

This commit is contained in:
PJ Dietz 2015-03-25 21:52:52 -04:00
parent a6b8a11cde
commit a5cb481d79
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace WellRESTed\Stream;
class StringStream extends StreamStream
{
public function __construct($string = "")
{
$handle = fopen("php://memory", "w+");
fwrite($handle, $string);
parent::__construct($handle);
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace WellRESTed\Test\Stream;
use WellRESTed\Stream\StringStream;
/**
* @covers WellRESTed\Stream\StringStream
* @uses WellRESTed\Stream\StreamStream
*/
class StringStreamTest extends \PHPUnit_Framework_TestCase
{
public function testCreatesInstance()
{
$stream = new StringStream();
$this->assertNotNull($stream);
}
public function testCreatesInstanceWithString()
{
$message = "Hello, World!";
$stream = new StringStream($message);
$this->assertEquals($message, (string) $stream);
}
public function testAllowsWriting()
{
$message = "Hello, World!";
$stream = new StringStream();
$stream->write("Hello,");
$stream->write(" World!");
$this->assertEquals($message, (string) $stream);
}
}