From bf331dbe5022927f42d3a4b9a7887e6992485209 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Tue, 17 Dec 2019 17:50:56 +0100 Subject: [PATCH] fixed TypeError in EnumSet::getBinaryBitsetLe() if EnumSet is using integer bitset internally --- src/EnumSet.php | 2 +- tests/MabeEnumTest/EnumSetTest.php | 46 ++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/EnumSet.php b/src/EnumSet.php index f29e2e85..df393366 100644 --- a/src/EnumSet.php +++ b/src/EnumSet.php @@ -1064,7 +1064,7 @@ private function doGetBinaryBitsetLeInt() */ public function getBinaryBitsetBe(): string { - return \strrev($this->bitset); + return \strrev($this->getBinaryBitsetLe()); } /** diff --git a/tests/MabeEnumTest/EnumSetTest.php b/tests/MabeEnumTest/EnumSetTest.php index f85da891..c1a714f8 100644 --- a/tests/MabeEnumTest/EnumSetTest.php +++ b/tests/MabeEnumTest/EnumSetTest.php @@ -378,7 +378,41 @@ public function testGetBinaryBitsetLe() $this->assertSame(3, $set->count()); } - public function testGetBinaryBitsetBe() + public function testGetBinaryBitsetBeInt() + { + $set = new EnumSet(Enum32::class); + + $enum1 = Enum32::ONE; + $enum2 = Enum32::TWO; + $enum3 = Enum32::THERTYTWO; + $enum4 = Enum32::THERTYONE; + + $set->add($enum1); + $this->assertSame("\x00\x00\x00\x01", $set->getBinaryBitsetBe()); + $this->assertTrue($set->has($enum1)); + + $set->add($enum2); + $this->assertSame("\x00\x00\x00\x03", $set->getBinaryBitsetBe()); + $this->assertTrue($set->has($enum2)); + + $set->add($enum3); + $this->assertSame("\x80\x00\x00\x03", $set->getBinaryBitsetBe()); + $this->assertTrue($set->has($enum3)); + + $set->add($enum4); + $this->assertSame("\xC0\x00\x00\x03", $set->getBinaryBitsetBe()); + $this->assertTrue($set->has($enum4)); + + $this->assertSame(4, $set->count()); + + $set->remove($enum2); + $this->assertSame("\xC0\x00\x00\x01", $set->getBinaryBitsetBe()); + $this->assertFalse($set->has($enum2)); + + $this->assertSame(3, $set->count()); + } + + public function testGetBinaryBitsetBeBin() { $set = new EnumSet(Enum65::class); @@ -387,25 +421,25 @@ public function testGetBinaryBitsetBe() $enum3 = Enum65::SIXTYFIVE; $enum4 = Enum65::SIXTYFOUR; - $set = $set->with($enum1); + $set->add($enum1); $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x01", $set->getBinaryBitsetBe()); $this->assertTrue($set->has($enum1)); - $set = $set->with($enum2); + $set->add($enum2); $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x03", $set->getBinaryBitsetBe()); $this->assertTrue($set->has($enum2)); - $set = $set->with($enum3); + $set->add($enum3); $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x00\x03", $set->getBinaryBitsetBe()); $this->assertTrue($set->has($enum3)); - $set = $set->with($enum4); + $set->add($enum4); $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x03", $set->getBinaryBitsetBe()); $this->assertTrue($set->has($enum4)); $this->assertSame(4, $set->count()); - $set = $set->without($enum2); + $set->remove($enum2); $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x01", $set->getBinaryBitsetBe()); $this->assertFalse($set->has($enum2));