|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Message\Encoding; |
| 4 | + |
| 5 | +use Http\Message\Encoding\FilteredStream; |
| 6 | +use PhpSpec\ObjectBehavior; |
| 7 | +use Psr\Http\Message\StreamInterface; |
| 8 | + |
| 9 | +class FilteredStreamStubSpec extends ObjectBehavior |
| 10 | +{ |
| 11 | + function it_throws_during_instantiation_with_invalid_read_filter_options(StreamInterface $stream) |
| 12 | + { |
| 13 | + $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); |
| 14 | + $this->beConstructedWith($stream, 'foo'); |
| 15 | + $this->shouldThrow('RuntimeException')->duringInstantiation(); |
| 16 | + } |
| 17 | + |
| 18 | + function it_throws_during_instantiation_with_invalid_write_filter_options(StreamInterface $stream) |
| 19 | + { |
| 20 | + $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); |
| 21 | + $this->beConstructedWith($stream, null, 'foo'); |
| 22 | + $this->shouldThrow('RuntimeException')->duringInstantiation(); |
| 23 | + } |
| 24 | + |
| 25 | + function let(StreamInterface $stream) |
| 26 | + { |
| 27 | + $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); |
| 28 | + $this->beConstructedWith($stream); |
| 29 | + } |
| 30 | + |
| 31 | + function it_reads() |
| 32 | + { |
| 33 | + // "This is a test stream" | base64_encode |
| 34 | + $stream = new MemoryStream('This is a test stream'); |
| 35 | + $this->beConstructedWith($stream); |
| 36 | + |
| 37 | + $this->read(4)->shouldReturn('VGhp'); |
| 38 | + } |
| 39 | + |
| 40 | + function it_gets_content() |
| 41 | + { |
| 42 | + // "This is a test stream" | base64_encode |
| 43 | + $stream = new MemoryStream('This is a test stream'); |
| 44 | + $this->beConstructedWith($stream); |
| 45 | + |
| 46 | + $this->getContents()->shouldReturn('VGhpcyBpcyBhIHRlc3Qgc3RyZWFt'); |
| 47 | + } |
| 48 | + |
| 49 | + function it_does_not_know_the_content_size() |
| 50 | + { |
| 51 | + $stream = new MemoryStream(gzencode('This is a test stream')); |
| 52 | + $this->beConstructedWith($stream); |
| 53 | + |
| 54 | + $this->getSize()->shouldBeNull(); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +class FilteredStreamStub extends FilteredStream |
| 59 | +{ |
| 60 | + protected function readFilter() |
| 61 | + { |
| 62 | + return 'convert.base64-encode'; |
| 63 | + } |
| 64 | + |
| 65 | + protected function writeFilter() |
| 66 | + { |
| 67 | + return 'convert.base64-encode'; |
| 68 | + } |
| 69 | +} |
0 commit comments