-
Notifications
You must be signed in to change notification settings - Fork 39
Encoding #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Encoding #5
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a301d77
Add Stream decorator
sagikazarmark 94cc919
Add stream encoding
sagikazarmark 946666d
Temporarily allow HHVM tests to fail, see #6
sagikazarmark c7fcd53
Applied fixes from StyleCI
sagikazarmark 7f7dd42
Skip specific tests on HHVM instead of allowing to fail, see #6
sagikazarmark 6478a77
Fix dependency issues with stream filter, closes #8
sagikazarmark 827ed4e
Add exception to zlib dependant streams when zlib is not enabled
sagikazarmark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php | ||
|
||
namespace spec\Http\Message\Decorator; | ||
|
||
use Http\Message\Decorator\StreamDecorator; | ||
use Psr\Http\Message\StreamInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class StreamDecoratorSpec extends ObjectBehavior | ||
{ | ||
function let(StreamInterface $stream) | ||
{ | ||
$this->beAnInstanceOf('spec\Http\Message\Decorator\StreamDecoratorStub', [$stream]); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('spec\Http\Message\Decorator\StreamDecoratorStub'); | ||
} | ||
|
||
function it_is_a_stream_decorator() | ||
{ | ||
$this->shouldUseTrait('Http\Message\Decorator\StreamDecorator'); | ||
} | ||
|
||
function it_casts_the_stream_to_string(StreamInterface $stream) | ||
{ | ||
$stream->__toString()->willReturn('body'); | ||
|
||
$this->__toString()->shouldReturn('body'); | ||
} | ||
|
||
function it_closes_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->close()->shouldBeCalled(); | ||
|
||
$this->close(); | ||
} | ||
|
||
function it_detaches_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->detach()->willReturn('detached'); | ||
|
||
$this->detach()->shouldReturn('detached'); | ||
} | ||
|
||
function it_returns_the_size_of_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->getSize()->willReturn(1234); | ||
|
||
$this->getSize()->shouldReturn(1234); | ||
} | ||
|
||
function it_returns_the_current_position_of_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->tell()->willReturn(0); | ||
|
||
$this->tell()->shouldReturn(0); | ||
} | ||
|
||
function it_checks_whether_the_stream_is_eof(StreamInterface $stream) | ||
{ | ||
$stream->eof()->willReturn(false); | ||
|
||
$this->eof()->shouldReturn(false); | ||
} | ||
|
||
function it_checks_whether_the_stream_is_seekable(StreamInterface $stream) | ||
{ | ||
$stream->isSeekable()->willReturn(true); | ||
|
||
$this->isSeekable()->shouldReturn(true); | ||
} | ||
|
||
function it_seeks_the_current_position_of_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->seek(0, SEEK_SET)->shouldBeCalled(); | ||
|
||
$this->seek(0); | ||
} | ||
|
||
function it_rewinds_to_the_beginning_of_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->rewind()->shouldBeCalled(); | ||
|
||
$this->rewind(); | ||
} | ||
|
||
function it_checks_whether_the_stream_is_writable(StreamInterface $stream) | ||
{ | ||
$stream->isWritable()->willReturn(true); | ||
|
||
$this->isWritable()->shouldReturn(true); | ||
} | ||
|
||
function it_writes_to_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->write('body')->shouldBeCalled(); | ||
|
||
$this->write('body'); | ||
} | ||
|
||
function it_checks_whether_the_stream_is_readable(StreamInterface $stream) | ||
{ | ||
$stream->isReadable()->willReturn(true); | ||
|
||
$this->isReadable()->shouldReturn(true); | ||
} | ||
|
||
function it_reads_from_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->read(4)->willReturn('body'); | ||
|
||
$this->read(4)->shouldReturn('body'); | ||
} | ||
|
||
function it_returns_the_contents_of_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->getContents()->willReturn('body'); | ||
|
||
$this->getContents()->shouldReturn('body'); | ||
} | ||
|
||
function it_returns_metadata_of_the_stream(StreamInterface $stream) | ||
{ | ||
$stream->getMetadata(null)->willReturn(['key' => 'value']); | ||
$stream->getMetadata('key')->willReturn('value'); | ||
$stream->getMetadata('key2')->willReturn(null); | ||
|
||
$this->getMetadata()->shouldReturn(['key' => 'value']); | ||
$this->getMetadata('key')->shouldReturn('value'); | ||
$this->getMetadata('key2')->shouldReturn(null); | ||
} | ||
|
||
function getMatchers() | ||
{ | ||
return [ | ||
'useTrait' => function ($subject, $trait) { | ||
return class_uses($subject, $trait); | ||
} | ||
]; | ||
} | ||
} | ||
|
||
class StreamDecoratorStub implements StreamInterface | ||
{ | ||
use StreamDecorator; | ||
|
||
public function __construct(StreamInterface $stream) | ||
{ | ||
$this->stream = $stream; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace spec\Http\Message\Encoding; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use PhpSpec\Exception\Example\SkippingException; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ChunkStreamSpec extends ObjectBehavior | ||
{ | ||
function let(StreamInterface $stream) | ||
{ | ||
if (defined('HHVM_VERSION')) { | ||
throw new SkippingException('Skipping test as there is no dechunk filter on hhvm'); | ||
} | ||
|
||
$this->beConstructedWith($stream); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Http\Message\Encoding\ChunkStream'); | ||
} | ||
|
||
function it_is_a_stream() | ||
{ | ||
$this->shouldImplement('Psr\Http\Message\StreamInterface'); | ||
} | ||
|
||
function it_chunks_content() | ||
{ | ||
$stream = new MemoryStream('This is a stream'); | ||
$this->beConstructedWith($stream, 6); | ||
|
||
$this->getContents()->shouldReturn("10\r\nThis is a stream\r\n0\r\n\r\n"); | ||
} | ||
|
||
function it_chunks_in_multiple() | ||
{ | ||
$stream = new MemoryStream('This is a stream', 6); | ||
$this->beConstructedWith($stream, 6); | ||
|
||
$this->getContents()->shouldReturn("6\r\nThis i\r\n6\r\ns a st\r\n4\r\nream\r\n0\r\n\r\n"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace spec\Http\Message\Encoding; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use PhpSpec\Exception\Example\SkippingException; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class CompressStreamSpec extends ObjectBehavior | ||
{ | ||
function let(StreamInterface $stream) | ||
{ | ||
if (defined('HHVM_VERSION')) { | ||
throw new SkippingException('Skipping test as zlib is not working on hhvm'); | ||
} | ||
|
||
$this->beConstructedWith($stream); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Http\Message\Encoding\CompressStream'); | ||
} | ||
|
||
function it_is_a_stream() | ||
{ | ||
$this->shouldImplement('Psr\Http\Message\StreamInterface'); | ||
} | ||
|
||
function it_reads() | ||
{ | ||
$stream = new MemoryStream('This is a test stream'); | ||
$this->beConstructedWith($stream); | ||
|
||
$stream->rewind(); | ||
$this->read(4)->shouldReturn(substr(gzcompress('This is a test stream'), 0, 4)); | ||
} | ||
|
||
function it_gets_content() | ||
{ | ||
$stream = new MemoryStream('This is a test stream'); | ||
$this->beConstructedWith($stream); | ||
|
||
$stream->rewind(); | ||
$this->getContents()->shouldReturn(gzcompress('This is a test stream')); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace spec\Http\Message\Encoding; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use PhpSpec\Exception\Example\SkippingException; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class DechunkStreamSpec extends ObjectBehavior | ||
{ | ||
function let(StreamInterface $stream) | ||
{ | ||
if (defined('HHVM_VERSION')) { | ||
throw new SkippingException('Skipping test as there is no dechunk filter on hhvm'); | ||
} | ||
|
||
$this->beConstructedWith($stream); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Http\Message\Encoding\DechunkStream'); | ||
} | ||
|
||
function it_is_a_stream() | ||
{ | ||
$this->shouldImplement('Psr\Http\Message\StreamInterface'); | ||
} | ||
|
||
function it_reads() | ||
{ | ||
$stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); | ||
$this->beConstructedWith($stream); | ||
|
||
$this->read(6)->shouldReturn('testte'); | ||
$this->read(6)->shouldReturn('st'); | ||
} | ||
|
||
function it_gets_content() | ||
{ | ||
$stream = new MemoryStream("4\r\ntest\r\n0\r\n\r\n\0"); | ||
$this->beConstructedWith($stream); | ||
|
||
$this->getContents()->shouldReturn('test'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace spec\Http\Message\Encoding; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use PhpSpec\Exception\Example\SkippingException; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class DecompressStreamSpec extends ObjectBehavior | ||
{ | ||
function let(StreamInterface $stream) | ||
{ | ||
if (defined('HHVM_VERSION')) { | ||
throw new SkippingException('Skipping test as zlib is not working on hhvm'); | ||
} | ||
|
||
$this->beConstructedWith($stream); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Http\Message\Encoding\DecompressStream'); | ||
} | ||
|
||
function it_is_a_stream() | ||
{ | ||
$this->shouldImplement('Psr\Http\Message\StreamInterface'); | ||
} | ||
|
||
function it_reads() | ||
{ | ||
// "This is a test stream" | deflate | ||
$stream = new MemoryStream(gzcompress('This is a test stream')); | ||
$this->beConstructedWith($stream); | ||
|
||
$this->read(4)->shouldReturn('This'); | ||
} | ||
|
||
function it_gets_content() | ||
{ | ||
// "This is a test stream" | deflate | ||
$stream = new MemoryStream(gzcompress('This is a test stream')); | ||
$this->beConstructedWith($stream); | ||
|
||
$this->getContents()->shouldReturn('This is a test stream'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace spec\Http\Message\Encoding; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class DeflateStreamSpec extends ObjectBehavior | ||
{ | ||
function let(StreamInterface $stream) | ||
{ | ||
$this->beConstructedWith($stream); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Http\Message\Encoding\DeflateStream'); | ||
} | ||
|
||
function it_is_a_stream() | ||
{ | ||
$this->shouldImplement('Psr\Http\Message\StreamInterface'); | ||
} | ||
|
||
function it_reads() | ||
{ | ||
$stream = new MemoryStream('This is a test stream'); | ||
$this->beConstructedWith($stream); | ||
|
||
$stream->rewind(); | ||
$this->read(4)->shouldReturn(substr(gzdeflate('This is a test stream'),0, 4)); | ||
} | ||
|
||
function it_gets_content() | ||
{ | ||
$stream = new MemoryStream('This is a test stream'); | ||
$this->beConstructedWith($stream); | ||
|
||
$stream->rewind(); | ||
$this->getContents()->shouldReturn(gzdeflate('This is a test stream')); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be in the require part, otherwise encoding does not work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets add these to suggest, and explain for what case one would want to use them in a project.