diff --git a/src/serializer/BitSet.php b/src/serializer/BitSet.php index 3c2d0e85..c848e148 100644 --- a/src/serializer/BitSet.php +++ b/src/serializer/BitSet.php @@ -129,7 +129,7 @@ public function write(PacketSerializer $out, int $length = null) : void{ $nextShift = $currentShift + self::SHIFT; if($nextShift >= self::INT_BITS){ $nextShift -= self::INT_BITS; - $bits |= ($parts[++$currentIndex] ?? 0) << (self::SHIFT - $nextShift); + $bits |= $parts[++$currentIndex] << (self::SHIFT - $nextShift); } $currentShift = $nextShift; 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 8e417e54..db2bc9ee 100644 --- a/tests/phpunit/BitSetTest.php +++ b/tests/phpunit/BitSetTest.php @@ -17,8 +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; -use function var_dump; class BitSetTest extends TestCase{ @@ -34,12 +32,12 @@ public function testBitSet() : void{ $packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $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); @@ -62,7 +60,7 @@ public function testBitSetParts() : void{ $packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $packetSerializer->getBuffer(), 0); $readTest = BitSet::read($packetSerializer, 128); - assertTrue($this->setsEqual($writeTest, $readTest)); + self::assertEqualBitSets($writeTest, $readTest); } public function testVarUnsignedLongCompatibility() : void{ @@ -75,23 +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()){ - var_dump($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)){ - var_dump($i, $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"); } }