Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EnumSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ private function doGetBinaryBitsetLeInt()
*/
public function getBinaryBitsetBe(): string
{
return \strrev($this->bitset);
return \strrev($this->getBinaryBitsetLe());
}

/**
Expand Down
46 changes: 40 additions & 6 deletions tests/MabeEnumTest/EnumSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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));

Expand Down