DroppingStreamTest.php 919 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace RingCentral\Tests\Psr7;
  3. use RingCentral\Psr7\BufferStream;
  4. use RingCentral\Psr7\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->assertEquals(2, $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->assertSame(0, $drop->write('test'));
  23. }
  24. }