From c9bdcae83cdd5388eee943bafea55327566d935b Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 24 Mar 2019 16:57:05 +0300 Subject: [PATCH] simplification of data providers --- tests/APILengthCoDecTest.php | 36 +++++--------------------------- tests/Helpers/BinaryStringHelperTest.php | 20 +++++------------- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/tests/APILengthCoDecTest.php b/tests/APILengthCoDecTest.php index 3ccfbef..d26870c 100644 --- a/tests/APILengthCoDecTest.php +++ b/tests/APILengthCoDecTest.php @@ -46,7 +46,7 @@ class APILengthCoDecTest extends TestCase public function encodedLengthProvider(): array { // [encoded length value, length value] - return [ + $default = [ [0, 0], // Low limit value for 1 byte encoded length [0x39, 0x39], // Arbitrary median value for 1 byte encoded length [0x7f, 0x7F], // High limit value for 1 byte encoded length @@ -63,29 +63,18 @@ class APILengthCoDecTest extends TestCase [0xE5AD736B, 0x5AD736B], // Arbitrary median value for 4 bytes encoded length [0xEFFFFFFF, 0xFFFFFFF], // High limit value for 4 bytes encoded length ]; - } - /** - * @dataProvider encodedLengthProvider64 - * @covers ::encodeLength - */ - public function test__encodeLength64($expected, $length) - { if (PHP_INT_SIZE < 8) { - $this->markTestSkipped('Available only on x64 CPUs'); + return $default; } - $this->assertEquals(BinaryStringHelper::IntegerToNBOBinaryString((int) $expected), APILengthCoDec::encodeLength($length)); - } - - public function encodedLengthProvider64(): array - { - // [encoded length value, length value] - return [ + $append = [ [0xF010000000, 0x10000000], // Low limit value for 5 bytes encoded length [0xF10D4EF9C3, 0x10D4EF9C3], // Arbitrary median value for 5 bytes encoded length [0xF7FFFFFFFF, 0x7FFFFFFFF], // High limit value for 5 bytes encoded length ]; + + return array_merge($default, $append); } /** @@ -100,21 +89,6 @@ class APILengthCoDecTest extends TestCase } /** - * @dataProvider encodedLengthProvider64 - * @covers ::decodeLength - */ - public function test__decodeLength64($encodedLength, $expected) - { - if (PHP_INT_SIZE < 8) { - $this->markTestSkipped('Available only on x64 CPUs'); - } - - // We have to provide $encodedLength as a "bytes" stream - $stream = new StringStream(BinaryStringHelper::IntegerToNBOBinaryString($encodedLength)); - $this->assertEquals($expected, APILengthCoDec::decodeLength($stream)); - } - - /** * @dataProvider decodeLengthControlWordProvider * @covers ::decodeLength * @expectedException \UnexpectedValueException diff --git a/tests/Helpers/BinaryStringHelperTest.php b/tests/Helpers/BinaryStringHelperTest.php index 403dadd..df12129 100644 --- a/tests/Helpers/BinaryStringHelperTest.php +++ b/tests/Helpers/BinaryStringHelperTest.php @@ -24,7 +24,7 @@ class BinaryStringHelperTest extends TestCase public function IntegerToNBOBinaryStringProvider(): array { - return [ + $default = [ [0, chr(0)], // lower boundary value [0xFFFFFFFF, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF)], // 32 bits maximal value @@ -37,27 +37,17 @@ class BinaryStringHelperTest extends TestCase // Let's try random value [0x390DDD99, chr(0x39) . chr(0x0D) . chr(0xDD) . chr(0x99)], ]; - } - /** - * @dataProvider IntegerToNBOBinaryStringProvider64 - * @covers ::IntegerToNBOBinaryString - */ - public function test__IntegerToNBOBinaryString64($value, $expected) - { if (PHP_INT_SIZE < 8) { - $this->markTestSkipped('Available only on x64 CPUs'); + return $default; } - $this->assertEquals($expected, BinaryStringHelper::IntegerToNBOBinaryString($value)); - } - - public function IntegerToNBOBinaryStringProvider64(): array - { - return [ + $append = [ // -1 is encoded with 0xFFFFFFF..... // 64 bits maximal value (on a 64 bits system only) [-1, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF)], // 64 bits upper boundary value ]; + + return array_merge($default, $append); } }