Add StringStream
This commit is contained in:
parent
a6b8a11cde
commit
a5cb481d79
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue