diff --git a/exercises/practice/circular-buffer/.meta/example.php b/exercises/practice/circular-buffer/.meta/example.php index d97f4989..09a92b9f 100644 --- a/exercises/practice/circular-buffer/.meta/example.php +++ b/exercises/practice/circular-buffer/.meta/example.php @@ -28,10 +28,6 @@ class BufferFullError extends Exception { } -class BufferEmptyError extends Exception -{ -} - class CircularBuffer { private int $capacity; @@ -47,13 +43,10 @@ public function __construct($capacity) $this->writePosition = 0; } - /** - * @throws BufferEmptyError - */ public function read() { if ($this->isEmpty()) { - throw new BufferEmptyError(); + return null; } $value = $this->buffer[$this->readPosition]; $this->buffer[$this->readPosition] = null; @@ -74,7 +67,6 @@ public function write($item): void } /** - * @throws BufferEmptyError * @throws BufferFullError */ public function forceWrite($item): void diff --git a/exercises/practice/circular-buffer/CircularBufferTest.php b/exercises/practice/circular-buffer/CircularBufferTest.php index 2044dcbe..1e7feb20 100644 --- a/exercises/practice/circular-buffer/CircularBufferTest.php +++ b/exercises/practice/circular-buffer/CircularBufferTest.php @@ -10,18 +10,15 @@ class CircularBufferTest extends TestCase { /** * uuid: 28268ed4-4ff3-45f3-820e-895b44d53dfa - * @throws BufferEmptyError */ public function testReadingEmptyBufferShouldFail(): void { $buffer = new CircularBuffer(1); - $this->expectException(BufferEmptyError::class); - $buffer->read(); + $this->assertNull($buffer->read()); } /** * uuid: 2e6db04a-58a1-425d-ade8-ac30b5f318f3 - * @throws BufferEmptyError * @throws BufferFullError */ public function testCanReadAnItemJustWritten(): void @@ -33,7 +30,6 @@ public function testCanReadAnItemJustWritten(): void /** * uuid: 90741fe8-a448-45ce-be2b-de009a24c144 - * @throws BufferEmptyError * @throws BufferFullError */ public function testEachItemMayOnlyBeReadOnce(): void @@ -41,13 +37,11 @@ public function testEachItemMayOnlyBeReadOnce(): void $buffer = new CircularBuffer(1); $buffer->write('1'); $this->assertSame('1', $buffer->read()); - $this->expectException(BufferEmptyError::class); - $buffer->read(); + $this->assertNull($buffer->read()); } /** * uuid: be0e62d5-da9c-47a8-b037-5db21827baa7 - * @throws BufferEmptyError * @throws BufferFullError */ public function testItemsAreReadInTheOrderTheyAreWritten(): void @@ -73,7 +67,6 @@ public function testFullBufferCantBeWrittenTo(): void /** * uuid: 547d192c-bbf0-4369-b8fa-fc37e71f2393 - * @throws BufferEmptyError * @throws BufferFullError */ public function testAReadFreesUpCapacityForAnotherWrite(): void @@ -87,7 +80,6 @@ public function testAReadFreesUpCapacityForAnotherWrite(): void /** * uuid: 04a56659-3a81-4113-816b-6ecb659b4471 - * @throws BufferEmptyError * @throws BufferFullError */ public function testReadPositionIsMaintainedEvenAcrossMultipleWrites(): void @@ -110,13 +102,11 @@ public function testItemsClearedOutOfBufferCantBeRead(): void $buffer = new CircularBuffer(1); $buffer->write('1'); $buffer->clear(); - $this->expectException(BufferEmptyError::class); - $buffer->read(); + $this->assertNull($buffer->read()); } /** * uuid: 45f3ae89-3470-49f3-b50e-362e4b330a59 - * @throws BufferEmptyError * @throws BufferFullError */ public function testClearFreesUpCapacityForAnotherWrite(): void @@ -130,7 +120,6 @@ public function testClearFreesUpCapacityForAnotherWrite(): void /** * uuid: e1ac5170-a026-4725-bfbe-0cf332eddecd - * @throws BufferEmptyError * @throws BufferFullError */ public function testClearDoesNothingOnEmptyBuffer(): void @@ -143,7 +132,6 @@ public function testClearDoesNothingOnEmptyBuffer(): void /** * uuid: 9c2d4f26-3ec7-453f-a895-7e7ff8ae7b5b - * @throws BufferEmptyError * @throws BufferFullError */ public function testForceWriteActsLikeWriteOnNonFullBuffer(): void @@ -157,7 +145,6 @@ public function testForceWriteActsLikeWriteOnNonFullBuffer(): void /** * uuid: 880f916b-5039-475c-bd5c-83463c36a147 - * @throws BufferEmptyError * @throws BufferFullError */ public function testForceWriteReplacesTheOldestItemOnFullBuffer(): void @@ -172,7 +159,6 @@ public function testForceWriteReplacesTheOldestItemOnFullBuffer(): void /** * uuid: bfecab5b-aca1-4fab-a2b0-cd4af2b053c3 - * @throws BufferEmptyError * @throws BufferFullError */ public function testForceWriteReplacesTheOldestItemRemainingInBufferFollowingARead(): void @@ -191,7 +177,6 @@ public function testForceWriteReplacesTheOldestItemRemainingInBufferFollowingARe /** * uuid: 9cebe63a-c405-437b-8b62-e3fdc1ecec5a - * @throws BufferEmptyError * @throws BufferFullError */ public function testInitialClearDoesNotAffectWrappingAround(): void @@ -204,7 +189,6 @@ public function testInitialClearDoesNotAffectWrappingAround(): void $buffer->forceWrite('4'); $this->assertSame('3', $buffer->read()); $this->assertSame('4', $buffer->read()); - $this->expectException(BufferEmptyError::class); - $buffer->read(); + $this->assertNull($buffer->read()); } }