From 001b83e50c2ba047eff51d7c78ad4cbb1225a72a Mon Sep 17 00:00:00 2001 From: Dries C Date: Tue, 3 Dec 2024 23:39:23 +0100 Subject: [PATCH] Rewrite BitSetTests --- tests/phpstan/configs/phpstan-bugs.neon | 9 --------- tests/phpunit/BitSetTest.php | 24 +++++++++--------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index 5d525eb1..969e9629 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -9,12 +9,3 @@ parameters: message: "#^Parameter \\#3 \\$packets of static method pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\PacketBatch\\:\\:encodePackets\\(\\) expects array\\, array\\ given\\.$#" count: 1 path: ../../../src/serializer/PacketBatch.php - - - message: "#^Parameter \\#2 \\$parts of class pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\BitSet constructor expects array\\, array\\ given\\.$#" - count: 1 - path: tests/phpunit/BitSetTest.php - - - - message: "#^Parameter \\#2 \\$parts of class pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\BitSet constructor expects array\\, array\\ given\\.$#" - count: 1 - path: tests/phpunit/BitSetTest.php diff --git a/tests/phpunit/BitSetTest.php b/tests/phpunit/BitSetTest.php index 38a9f556..c40b9a04 100644 --- a/tests/phpunit/BitSetTest.php +++ b/tests/phpunit/BitSetTest.php @@ -17,7 +17,6 @@ use PHPUnit\Framework\TestCase; use pocketmine\network\mcpe\protocol\serializer\BitSet; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; -use function PHPUnit\Framework\assertTrue; class BitSetTest extends TestCase{ @@ -33,12 +32,12 @@ public function testBitSet() : void{ $packetSerializer = PacketSerializer::decoder($packetSerializer->getBuffer(), 0); $readTest = BitSet::read($packetSerializer, 65); - assertTrue($this->setsEqual($writeTest, $readTest)); + self::assertEqualBitSets($writeTest, $readTest); } public function testBitSetConstructor() : void{ - $test = new BitSet(65, [-9223372036854775808, 1]); - $test2 = new BitSet(65, [-9223372036854775808]); + $test = new BitSet(65, [-9223372036854775807 - 1, 1]); + $test2 = new BitSet(65, [-9223372036854775807 - 1]); $test2->set(64, true); @@ -61,7 +60,7 @@ public function testBitSetParts() : void{ $packetSerializer = PacketSerializer::decoder($packetSerializer->getBuffer(), 0); $readTest = BitSet::read($packetSerializer, 128); - assertTrue($this->setsEqual($writeTest, $readTest)); + self::assertEqualBitSets($writeTest, $readTest); } public function testVarUnsignedLongCompatibility() : void{ @@ -74,21 +73,16 @@ public function testVarUnsignedLongCompatibility() : void{ $expectedResult = new BitSet(64); $expectedResult->set(63, true); - assertTrue($this->setsEqual($expectedResult, $readTest)); + self::assertEqualBitSets($expectedResult, $readTest); } - private function setsEqual(BitSet $a, BitSet $b) : bool{ - $length = $a->getLength(); - if($length !== $b->getLength()){ - return false; - } + private static function assertEqualBitSets(BitSet $a, BitSet $b) : void{ + self::assertEquals($length = $a->getLength(), $b->getLength(), "BitSet lengths are not equal"); for($i = 0; $i < $length; ++$i){ - if($a->get($i) !== $b->get($i)){ - return false; - } + self::assertEquals($a->get($i), $b->get($i), "BitSet values at index $i are not equal"); } - return $a->getPartsCount() === $b->getPartsCount(); + self::assertEquals($a->getPartsCount(), $b->getPartsCount(), "BitSet parts count is not equal"); } }