Skip to content

Unit test: ReadBuffer — missing tests for getUint8, getUint64, getInt64, getObjectArray, getPosition, getRemainingBytes#305

Merged
s2x merged 1 commit intomainfrom
oda-187-unit-test-readbuffer-missing-tests-for-g
Mar 29, 2026
Merged

Unit test: ReadBuffer — missing tests for getUint8, getUint64, getInt64, getObjectArray, getPosition, getRemainingBytes#305
s2x merged 1 commit intomainfrom
oda-187-unit-test-readbuffer-missing-tests-for-g

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented Mar 29, 2026

Closes #187

Problem

`ReadBuffer` (225 lines, 18 public methods) has good underflow error coverage but is missing tests for several read methods:

  1. `getUint8()` — only tested via underflow, no happy-path test
  2. `getUint64()` — only tested via underflow, no happy-path test
  3. `getInt64()` — only tested via underflow, no happy-path test
  4. `getInt16()` — only tested via underflow, no happy-path test
  5. `getInt32()` — only tested via underflow, no happy-path test
  6. `getObjectArray(string $class)` — never tested at all
  7. `getPosition()` — never tested directly
  8. `getRemainingBytes()` — only tested for empty/fully-read, not mid-read
  9. `peekUint16()` — only tested via underflow, no happy-path test (peek should not advance position)
  10. `skip()` — only tested via underflow, no happy-path test
  11. `readBytes()` — only tested via underflow, no happy-path test

Expected tests

```php
public function testGetUint8(): void
{
$buf = new ReadBuffer("\xFF");
$this->assertSame(255, $buf->getUint8());
}

public function testGetUint64(): void
{
$buf = new ReadBuffer(pack('J', 12345678901234));
$this->assertSame(12345678901234, $buf->getUint64());
}

public function testGetInt64Negative(): void
{
$buf = new ReadBuffer(pack('q', -1)); // Note: big-endian
$this->assertSame(-1, $buf->getInt64());
}

public function testPeekUint16DoesNotAdvancePosition(): void
{
$buf = new ReadBuffer("\x00\x01\x00\x02");
$peeked = $buf->peekUint16();
$read = $buf->getUint16();
$this->assertSame($peeked, $read); // Same value — position didn't move
}

public function testGetPositionAdvancesCorrectly(): void
{
$buf = new ReadBuffer("\x00\x01\x00\x02\x00\x03");
$this->assertSame(0, $buf->getPosition());
$buf->getUint16();
$this->assertSame(2, $buf->getPosition());
$buf->getUint32();
$this->assertSame(6, $buf->getPosition());
}

public function testGetObjectArray(): void
{
// Build binary for array of KeyValue objects
// Verify correct deserialization
}
```

Acceptance criteria

  • Happy-path tests for all 18 public methods
  • `peekUint16` verified to not advance position
  • `getPosition()` verified after each read operation
  • `getRemainingBytes()` verified mid-read
  • `getObjectArray()` tested with a real VO class
  • Signed integer tests with negative values
  • Large unsigned values (near max uint64)

Add 22 new test methods covering happy-path scenarios:
- getUint8, getUint64, getInt16, getInt32, getInt64 (with negative and boundary values)
- getPosition, getRemainingBytes (position tracking and mid-read scenarios)
- peekUint16 (verifies position unchanged after peek)
- skip (position advancement)
- readBytes (various lengths and position tracking)
- getObjectArray (with KeyValue VO, empty and populated arrays)

Increases test coverage from 24 to 46 tests (92 assertions).
@s2x s2x merged commit 79e2154 into main Mar 29, 2026
7 checks passed
@s2x s2x deleted the oda-187-unit-test-readbuffer-missing-tests-for-g branch March 29, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit test: ReadBuffer — missing tests for getUint8, getUint64, getInt64, getObjectArray, getPosition, getRemainingBytes

1 participant