Merge pull request #18 from wellrestedphp/fix-tests
Fix broken test for Stream
This commit is contained in:
commit
66ff6d2fc1
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace WellRESTed\Message;
|
||||
|
||||
// Declare functions in this namespace so the class under test will use these
|
||||
// instead of the internal global functions during testing.
|
||||
|
||||
class StreamHelper
|
||||
{
|
||||
public static $fail = false;
|
||||
}
|
||||
|
||||
function fseek($resource, $offset, $whence = SEEK_SET)
|
||||
{
|
||||
if (StreamHelper::$fail) {
|
||||
return -1;
|
||||
}
|
||||
return \fseek($resource, $offset, $whence);
|
||||
}
|
||||
|
||||
function ftell($resource)
|
||||
{
|
||||
if (StreamHelper::$fail) {
|
||||
return false;
|
||||
}
|
||||
return \ftell($resource);
|
||||
}
|
||||
|
||||
function rewind($resource)
|
||||
{
|
||||
if (StreamHelper::$fail) {
|
||||
return false;
|
||||
}
|
||||
return \rewind($resource);
|
||||
}
|
||||
|
|
@ -5,8 +5,11 @@ namespace WellRESTed\Test\Unit\Message;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use WellRESTed\Message\Stream;
|
||||
use WellRESTed\Message\StreamHelper;
|
||||
use WellRESTed\Test\TestCase;
|
||||
|
||||
require_once __DIR__ . "/../../../src/StreamHelper.php";
|
||||
|
||||
class StreamTest extends TestCase
|
||||
{
|
||||
private $resource;
|
||||
|
|
@ -18,6 +21,7 @@ class StreamTest extends TestCase
|
|||
$this->resource = fopen("php://memory", "w+");
|
||||
$this->resourceDevNull = fopen("/dev/null", "r");
|
||||
fwrite($this->resource, $this->content);
|
||||
StreamHelper::$fail = false;
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
|
|
@ -106,7 +110,8 @@ class StreamTest extends TestCase
|
|||
|
||||
public function testTellThrowsRuntimeExceptionWhenUnableToReadStreamPosition()
|
||||
{
|
||||
$stream = new Stream($this->resourceDevNull);
|
||||
StreamHelper::$fail = true;
|
||||
$stream = new Stream($this->resource);
|
||||
$this->expectException(RuntimeException::class);
|
||||
$stream->tell();
|
||||
}
|
||||
|
|
@ -136,7 +141,8 @@ class StreamTest extends TestCase
|
|||
|
||||
public function testSeekThrowsRuntimeExceptionWhenUnableToSeek()
|
||||
{
|
||||
$stream = new Stream($this->resourceDevNull);
|
||||
StreamHelper::$fail = true;
|
||||
$stream = new Stream($this->resource);
|
||||
$this->expectException(RuntimeException::class);
|
||||
$stream->seek(10);
|
||||
}
|
||||
|
|
@ -151,7 +157,8 @@ class StreamTest extends TestCase
|
|||
|
||||
public function testRewindThrowsRuntimeExceptionWhenUnableToRewind()
|
||||
{
|
||||
$stream = new Stream($this->resourceDevNull);
|
||||
StreamHelper::$fail = true;
|
||||
$stream = new Stream($this->resource);
|
||||
$this->expectException(RuntimeException::class);
|
||||
$stream->rewind();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue