-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent cache corruption when normalizing and mapping to enum
- Loading branch information
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/Integration/NonRegression/NormalizeEnumDoesNotBreakMapperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CuyZ\Valinor\Tests\Integration\NonRegression; | ||
|
||
use CuyZ\Valinor\Normalizer\Format; | ||
use CuyZ\Valinor\Tests\Fixture\Enum\BackedStringEnum; | ||
use CuyZ\Valinor\Tests\Integration\IntegrationTestCase; | ||
|
||
final class NormalizeEnumDoesNotBreakMapperTest extends IntegrationTestCase | ||
{ | ||
/** | ||
* The normalizer will at some point fetch the class definition of the enum, | ||
* we need to ensure an `EnumType` is used and not a `NativeClassType`, | ||
* otherwise the cache would be corrupted for further usage. | ||
* | ||
* @see https://github.com/CuyZ/Valinor/issues/562 | ||
*/ | ||
public function test_normalizing_enum_and_then_map_value_on_same_enum_class_does_not_break(): void | ||
{ | ||
$mapperBuilder = $this->mapperBuilder(); | ||
|
||
$mapperBuilder->normalizer(Format::array())->normalize(BackedStringEnum::FOO); | ||
|
||
$result = $mapperBuilder->mapper()->map(BackedStringEnum::class, 'foo'); | ||
|
||
self::assertSame(BackedStringEnum::FOO, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters