forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore reverse lookup determinism (doctrine#6097)
In doctrine#5036, it looks like I wrongly assumed I wouldn't be able to allow having 2 classes of the same type in the type registry without also allowing having 2 objects of the same type. `array_search` can perfectly tell the difference between both situations, so let us continue forbidding that last part, it will allow us to make sure a given type matches exactly one name.
- Loading branch information
Showing
4 changed files
with
69 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Types\Exception; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Exception; | ||
|
||
use function get_debug_type; | ||
use function spl_object_hash; | ||
use function sprintf; | ||
|
||
/** @psalm-immutable */ | ||
final class TypeAlreadyRegistered extends Exception implements TypesException | ||
{ | ||
public static function new(Type $type): self | ||
{ | ||
return new self(sprintf( | ||
'Type of the class %s@%s is already registered.', | ||
get_debug_type($type), | ||
spl_object_hash($type), | ||
)); | ||
} | ||
} |
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
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Types\Exception; | ||
|
||
use Doctrine\DBAL\Types\Exception\TypeAlreadyRegistered; | ||
use Doctrine\DBAL\Types\Type; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TypeAlreadyRegisteredTest extends TestCase | ||
{ | ||
public function testNew(): void | ||
{ | ||
$exception = TypeAlreadyRegistered::new(Type::getType('string')); | ||
|
||
self::assertMatchesRegularExpression( | ||
'/Type of the class Doctrine\\\DBAL\\\Types\\\StringType@([0-9a-zA-Z]+) is already registered./', | ||
$exception->getMessage(), | ||
); | ||
} | ||
} |
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