123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\Intl\Tests\Data\Util;
- use PHPUnit\Framework\TestCase;
- use Symfony\Component\Intl\Data\Util\RingBuffer;
- /**
- * @author Bernhard Schussek <bschussek@gmail.com>
- */
- class RingBufferTest extends TestCase
- {
- /**
- * @var RingBuffer
- */
- private $buffer;
- protected function setUp()
- {
- $this->buffer = new RingBuffer(2);
- }
- public function testWriteWithinBuffer()
- {
- $this->buffer[0] = 'foo';
- $this->buffer['bar'] = 'baz';
- $this->assertTrue(isset($this->buffer[0]));
- $this->assertTrue(isset($this->buffer['bar']));
- $this->assertSame('foo', $this->buffer[0]);
- $this->assertSame('baz', $this->buffer['bar']);
- }
- public function testWritePastBuffer()
- {
- $this->buffer[0] = 'foo';
- $this->buffer['bar'] = 'baz';
- $this->buffer[2] = 'bam';
- $this->assertTrue(isset($this->buffer['bar']));
- $this->assertTrue(isset($this->buffer[2]));
- $this->assertSame('baz', $this->buffer['bar']);
- $this->assertSame('bam', $this->buffer[2]);
- }
- /**
- * @expectedException \Symfony\Component\Intl\Exception\OutOfBoundsException
- */
- public function testReadNonExistingFails()
- {
- $this->buffer['foo'];
- }
- public function testQueryNonExisting()
- {
- $this->assertFalse(isset($this->buffer['foo']));
- }
- public function testUnsetNonExistingSucceeds()
- {
- unset($this->buffer['foo']);
- $this->assertFalse(isset($this->buffer['foo']));
- }
- /**
- * @expectedException \Symfony\Component\Intl\Exception\OutOfBoundsException
- */
- public function testReadOverwrittenFails()
- {
- $this->buffer[0] = 'foo';
- $this->buffer['bar'] = 'baz';
- $this->buffer[2] = 'bam';
- $this->buffer[0];
- }
- public function testQueryOverwritten()
- {
- $this->assertFalse(isset($this->buffer[0]));
- }
- public function testUnsetOverwrittenSucceeds()
- {
- $this->buffer[0] = 'foo';
- $this->buffer['bar'] = 'baz';
- $this->buffer[2] = 'bam';
- unset($this->buffer[0]);
- $this->assertFalse(isset($this->buffer[0]));
- }
- }
|