Skip to content

Commit 67a82c0

Browse files
committed
Test that readShort() behaves properly with too much and too little data
this is a half-assed test, but readShort() is fairly representative of most of the code, so it should be good enough for now.
1 parent 4c856ad commit 67a82c0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/phpunit/BinaryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,19 @@ public function testReadSignedByteWithEmptyString() : void{
3636
$this->expectException(BinaryDataException::class);
3737
Binary::readSignedByte("");
3838
}
39+
40+
/**
41+
* Passing too much data is OK; we just take the first N bytes as needed.
42+
*/
43+
public function testReadShortTooMuchData() : void{
44+
$expected = 19132;
45+
$data = Binary::writeShort($expected) . "\x00\x00";
46+
$number = Binary::readShort($data);
47+
self::assertSame($expected, $number);
48+
}
49+
50+
public function testReadShortNotEnoughData() : void{
51+
$this->expectException(BinaryDataException::class);
52+
Binary::readShort("\x01");
53+
}
3954
}

0 commit comments

Comments
 (0)