Skip to content

Commit

Permalink
Merge pull request #137 from marc-mabe/fix-EnumSet-getBinaryBitsetLe
Browse files Browse the repository at this point in the history
fixed TypeError in EnumSet::getBinaryBitsetLe() …
  • Loading branch information
marc-mabe authored Dec 18, 2019
2 parents c60b29b + bf331db commit e6113cf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
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

0 comments on commit e6113cf

Please sign in to comment.