DroppingStreamTest.php 916 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace GuzzleHttp\Tests\Stream;
  3. use GuzzleHttp\Stream\BufferStream;
  4. use GuzzleHttp\Stream\DroppingStream;
  5. class DroppingStreamTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testBeginsDroppingWhenSizeExceeded()
  8. {
  9. $stream = new BufferStream();
  10. $drop = new DroppingStream($stream, 5);
  11. $this->assertEquals(3, $drop->write('hel'));
  12. $this->assertFalse($drop->write('lo'));
  13. $this->assertEquals(5, $drop->getSize());
  14. $this->assertEquals('hello', $drop->read(5));
  15. $this->assertEquals(0, $drop->getSize());
  16. $drop->write('12345678910');
  17. $this->assertEquals(5, $stream->getSize());
  18. $this->assertEquals(5, $drop->getSize());
  19. $this->assertEquals('12345', (string) $drop);
  20. $this->assertEquals(0, $drop->getSize());
  21. $drop->write('hello');
  22. $this->assertFalse($drop->write('test'));
  23. }
  24. }