NoSeekStreamTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace GuzzleHttp\Tests\Stream;
  3. use GuzzleHttp\Stream\Stream;
  4. use GuzzleHttp\Stream\NoSeekStream;
  5. /**
  6. * @covers GuzzleHttp\Stream\NoSeekStream
  7. * @covers GuzzleHttp\Stream\StreamDecoratorTrait
  8. */
  9. class NoSeekStreamTest extends \PHPUnit_Framework_TestCase
  10. {
  11. public function testCannotSeek()
  12. {
  13. $s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
  14. ->setMethods(['isSeekable', 'seek'])
  15. ->getMockForAbstractClass();
  16. $s->expects($this->never())->method('seek');
  17. $s->expects($this->never())->method('isSeekable');
  18. $wrapped = new NoSeekStream($s);
  19. $this->assertFalse($wrapped->isSeekable());
  20. $this->assertFalse($wrapped->seek(2));
  21. }
  22. public function testHandlesClose()
  23. {
  24. $s = Stream::factory('foo');
  25. $wrapped = new NoSeekStream($s);
  26. $wrapped->close();
  27. $this->assertFalse($wrapped->write('foo'));
  28. }
  29. public function testCanAttach()
  30. {
  31. $s1 = Stream::factory('foo');
  32. $s2 = Stream::factory('bar');
  33. $wrapped = new NoSeekStream($s1);
  34. $wrapped->attach($s2->detach());
  35. $this->assertEquals('bar', (string) $wrapped);
  36. }
  37. }