Closed szepeviktor closed 8 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
524d1a7
) 100.00% compared to head (972fbf7
) 100.00%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hi, I think you found quite the bug here. As far as I can see, the __toString method on the EnumCase class is only there to filter out duplicates, but that is not done directly. IMHO we just add the duplicate cases instead of silently dropping them and let CI pick those up for manual review. I think the best fix in that case would be this:
public function __toString(): string
{
- return NameNormalizer::normalize($this->name);
+ return NameNormalizer::normalize($this->name) . NameNormalizer::normalize($this->value);
}
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PrinsFrank\Standards\Dev\DataTarget\EnumCase;
/** @coversDefaultClass \PrinsFrank\Standards\Dev\DataTarget\EnumCase */
class EnumCaseTest extends TestCase
{
/** @covers ::__toString */
public function testToStringCanBeUsedToDetectIdenticalEnumNameValuePairs(): void
{
static::assertEquals(
[
new EnumCase('', '')
],
array_unique(
[
new EnumCase('', '')
]
)
);
static::assertEquals(
[
new EnumCase('foo', 'bar')
],
array_unique(
[
new EnumCase('foo', 'bar')
]
)
);
static::assertEquals(
[
new EnumCase('foo', 'bar')
],
array_unique(
[
new EnumCase('foo', 'bar'),
new EnumCase('foo', 'bar')
]
)
);
static::assertEquals(
[
new EnumCase('foo', 'bar'),
new EnumCase('foo', 'bop'),
],
array_unique(
[
new EnumCase('foo', 'bar'),
new EnumCase('foo', 'bop')
]
)
);
}
}
What do you think?
FYI: there's currently no location the EnumTestCase would make sense in, so you can move the files from tests/Unit/
to tests/src/Unit
and add a new tests/dev
folder I guess?
This looks like a change we'll need anyway, so I'll merge this. Thanks!!
You know what you do!
💥 Allow duplicated keys.
For #182