forked from CuyZ/Valinor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle class name collision while parsing types inside a class
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
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
33 changes: 33 additions & 0 deletions
33
tests/Integration/Mapping/ClassNameCollisionTestCollision.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,33 @@ | ||
<?php | ||
|
||
namespace CuyZ\Valinor\Tests\Integration\Mapping; | ||
|
||
use CuyZ\Valinor\Mapper\MappingError; | ||
use CuyZ\Valinor\MapperBuilder; | ||
use CuyZ\Valinor\Tests\Integration\IntegrationTest; | ||
use CuyZ\Valinor\Tests\Integration\Mapping\Fixture\Error; | ||
|
||
final class ClassNameCollisionTestCollision extends IntegrationTest | ||
{ | ||
public function test_mapping_to_class_with_same_class_name_as_native_class_works_properly(): void | ||
{ | ||
try { | ||
$result = (new MapperBuilder()) | ||
->mapper() | ||
->map(ObjectWithErrorsClassNameCollision::class, ['foo', 'bar']); | ||
} catch (MappingError $error) { | ||
$this->mappingFail($error); | ||
} | ||
|
||
self::assertSame('foo', $result->errors[0]->message); | ||
self::assertSame('bar', $result->errors[1]->message); | ||
} | ||
} | ||
|
||
final class ObjectWithErrorsClassNameCollision | ||
{ | ||
public function __construct( | ||
/** @var list<Error> */ | ||
public array $errors | ||
) {} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace CuyZ\Valinor\Tests\Integration\Mapping\Fixture; | ||
|
||
/** | ||
* Has the same name of the native class `Error` on purpose. | ||
*/ | ||
final class Error | ||
{ | ||
public function __construct( | ||
public string $message | ||
) {} | ||
} |