NoSeekStreamTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace RingCentral\Tests\Psr7;
  3. use RingCentral\Psr7;
  4. use RingCentral\Psr7\NoSeekStream;
  5. /**
  6. * @covers RingCentral\Psr7\NoSeekStream
  7. * @covers RingCentral\Psr7\StreamDecoratorTrait
  8. */
  9. class NoSeekStreamTest extends \PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @expectedException \RuntimeException
  13. * @expectedExceptionMessage Cannot seek a NoSeekStream
  14. */
  15. public function testCannotSeek()
  16. {
  17. $s = $this->getMockBuilder('Psr\Http\Message\StreamInterface')
  18. ->setMethods(array('isSeekable', 'seek'))
  19. ->getMockForAbstractClass();
  20. $s->expects($this->never())->method('seek');
  21. $s->expects($this->never())->method('isSeekable');
  22. $wrapped = new NoSeekStream($s);
  23. $this->assertFalse($wrapped->isSeekable());
  24. $wrapped->seek(2);
  25. }
  26. /**
  27. * @expectedException \RuntimeException
  28. * @expectedExceptionMessage Cannot write to a non-writable stream
  29. */
  30. public function testHandlesClose()
  31. {
  32. $s = Psr7\stream_for('foo');
  33. $wrapped = new NoSeekStream($s);
  34. $wrapped->close();
  35. $wrapped->write('foo');
  36. }
  37. }