Skip to content

Commit 9201efc

Browse files
committed
Fix BufferUnpacker constructor to check against UnpackOptions instead of PackOptions
1 parent b12c0f0 commit 9201efc

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/BufferUnpacker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(string $buffer = '', $options = null, array $extensi
3939
{
4040
if (\is_null($options)) {
4141
$options = UnpackOptions::fromDefaults();
42-
} elseif (!$options instanceof PackOptions) {
42+
} elseif (!$options instanceof UnpackOptions) {
4343
$options = UnpackOptions::fromBitmask($options);
4444
}
4545

tests/Unit/BufferUnpackerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,24 @@ public function testTryUnpackTruncatesBuffer() : void
331331
self::fail('Buffer was not truncated.');
332332
}
333333

334+
/**
335+
* @dataProvider provideOptionsData
336+
* @doesNotPerformAssertions
337+
*/
338+
public function testConstructorSetsOptions($options) : void
339+
{
340+
new BufferUnpacker('', $options);
341+
}
342+
343+
public function provideOptionsData() : iterable
344+
{
345+
return [
346+
[0],
347+
[null],
348+
[UnpackOptions::fromDefaults()],
349+
];
350+
}
351+
334352
/**
335353
* @dataProvider provideInvalidOptionsData
336354
*/

tests/Unit/PackerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ public function provideOptionsData() : array
7676
[null, [0 => 1], "\x91\x01"],
7777
[PackOptions::DETECT_STR_BIN, "\x80", "\xc4\x01\x80"],
7878
[PackOptions::DETECT_STR_BIN, 'a', "\xa1\x61"],
79+
[PackOptions::fromDefaults(), "\x80", "\xc4\x01\x80"],
80+
[PackOptions::fromDefaults(), 'a', "\xa1\x61"],
7981
[PackOptions::FORCE_FLOAT64, 0.0, "\xcb\x00\x00\x00\x00\x00\x00\x00\x00"],
82+
[PackOptions::fromDefaults(), 0.0, "\xcb\x00\x00\x00\x00\x00\x00\x00\x00"],
8083
[PackOptions::DETECT_ARR_MAP, [1 => 2], "\x81\x01\x02"],
8184
[PackOptions::DETECT_ARR_MAP, [0 => 1], "\x91\x01"],
85+
[PackOptions::fromDefaults(), [1 => 2], "\x81\x01\x02"],
86+
[PackOptions::fromDefaults(), [0 => 1], "\x91\x01"],
8287
[PackOptions::FORCE_STR, "\x80", "\xa1\x80"],
8388
[PackOptions::FORCE_BIN, 'a', "\xc4\x01\x61"],
8489
[PackOptions::FORCE_ARR, [1 => 2], "\x91\x02"],

0 commit comments

Comments
 (0)