Skip to content

Commit 9e92312

Browse files
committed
Fixed #60: Infinitive loop on counting empty set based on empty enum
1 parent bed0b55 commit 9e92312

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/EnumSet.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,12 @@ public function count()
189189
{
190190
$cnt = 0;
191191
$ord = 0;
192-
do {
192+
193+
while ($ord !== $this->ordinalMax) {
193194
if ($this->getBit($ord++)) {
194195
++$cnt;
195196
}
196-
} while ($ord !== $this->ordinalMax);
197+
}
197198

198199
return $cnt;
199200
}

tests/MabeEnumTest/EnumSetTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MabeEnumTest;
44

55
use MabeEnum\EnumSet;
6+
use MabeEnumTest\TestAsset\EmptyEnum;
67
use MabeEnumTest\TestAsset\EnumBasic;
78
use MabeEnumTest\TestAsset\EnumInheritance;
89
use MabeEnumTest\TestAsset\Enum32;
@@ -317,4 +318,10 @@ public function testFalseBitsetArgumentExceptionIfNotString()
317318
$enum = new EnumSet('MabeEnumTest\TestAsset\Enum65');
318319
$enum->setBitset(0);
319320
}
321+
322+
public function testCountingEmptyEnumEmptySet()
323+
{
324+
$set = new EnumSet('MabeEnumTest\TestAsset\EmptyEnum');
325+
$this->assertSame(0, $set->count());
326+
}
320327
}

0 commit comments

Comments
 (0)