Skip to content

Commit eea8a03

Browse files
committed
test(CBOR): Improve test coverage for CBOR and TextString
1 parent 81c230b commit eea8a03

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/CBOR/CBOR.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public static function decode(string $data): int|string
4040
return UnsignedInteger::decode($data);
4141
}
4242

43-
throw new \ValueError("Unsupported type");
43+
throw new \ValueError("Unsupported type.");
4444
}
4545
}

tests/Unit/CBOR/CBORTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ public function testDecode(int|string $expected, string $data): void
3232
$this->assertSame($expected, $actual);
3333
}
3434

35+
public function testCBORDecodeThrowsExceptionWhenPassedUnsupportedType(): void
36+
{
37+
$this->expectException(\ValueError::class);
38+
$this->expectExceptionMessage('Unsupported type.');
39+
40+
CBOR::decode("\x80"); // CBOR array
41+
}
42+
43+
public function testCBOREncodeThrowsExceptionWhenPassedUnsupportedType(): void
44+
{
45+
$this->expectException(\ValueError::class);
46+
$this->expectExceptionMessage('Unsupported type: array');
47+
48+
CBOR::encode(array());
49+
}
50+
3551
/**
3652
* @return array[]
3753
*/

tests/Unit/CBOR/MajorTypes/TextStringTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public static function provideValidCases(): array
4646
["foob", "\x64"],
4747
["fooba", "\x65"],
4848
["foobar", "\x66"],
49+
[
50+
"This is a longer string. This is a longer string. This is a longer string. This is a longer string.",
51+
"\x78\x63"
52+
],
4953
[
5054
"This is a longer string. This is a longer string. This is a longer string. This is a longer string.
5155
This is a longer string. This is a longer string. This is a longer string. This is a longer string.

0 commit comments

Comments
 (0)