diff --git a/composer.json b/composer.json index b763343..97b43fc 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,13 @@ } ], "require": { - "php": "^7.4 || ^8.0", - "doctrine/dbal": "^2.8 || ^3.0", + "php": "^8.0", + "doctrine/dbal": "^4.0", "ramsey/uuid": "^3.9.7 || ^4.0" }, "require-dev": { "captainhook/plugin-composer": "^5.3", - "doctrine/orm": "^2.5", + "doctrine/orm": "^3.0", "ergebnis/composer-normalize": "^2.28.3", "mockery/mockery": "^1.5", "php-parallel-lint/php-console-highlighter": "^1.0", diff --git a/src/UuidBinaryOrderedTimeType.php b/src/UuidBinaryOrderedTimeType.php index e6e54ce..59c47cc 100644 --- a/src/UuidBinaryOrderedTimeType.php +++ b/src/UuidBinaryOrderedTimeType.php @@ -17,6 +17,9 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Ramsey\Uuid\Codec\OrderedTimeCodec; use Ramsey\Uuid\Exception\UnsupportedOperationException; @@ -52,7 +55,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st { return $platform->getBinaryTypeDeclarationSQL( [ - 'length' => '16', + 'length' => 16, 'fixed' => true, ], ); @@ -76,7 +79,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?UuidInte try { return $this->decode($value); } catch (Throwable $e) { - throw ConversionException::conversionFailed($value, self::NAME); + throw ValueNotConvertible::new($value, self::NAME); } } @@ -105,20 +108,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str // Ignore the exception and pass through. } - throw ConversionException::conversionFailed($value, self::NAME); + throw InvalidType::new($value, self::NAME, ['null', 'string', UuidInterface::class]); } - public function getName(): string - { - return self::NAME; - } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } - - public function getBindingType(): int + public function getBindingType(): ParameterType { return ParameterType::BINARY; } @@ -158,7 +151,7 @@ private function assertUuidV1(UuidInterface $value): void { /** @psalm-suppress DeprecatedMethod */ if ($value->getVersion() !== 1) { - throw ConversionException::conversionFailedFormat( + throw InvalidFormat::new( $value->toString(), self::NAME, self::ASSERT_FORMAT, @@ -184,7 +177,7 @@ private function decode(string $bytes): UuidInterface try { $decoded = $this->getCodec()->decodeBytes($bytes); } catch (UnsupportedOperationException $e) { - throw ConversionException::conversionFailedFormat( + throw InvalidFormat::new( bin2hex($bytes), self::NAME, self::ASSERT_FORMAT, diff --git a/src/UuidBinaryType.php b/src/UuidBinaryType.php index 3f66f32..1b89029 100644 --- a/src/UuidBinaryType.php +++ b/src/UuidBinaryType.php @@ -17,6 +17,8 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; @@ -43,7 +45,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st { return $platform->getBinaryTypeDeclarationSQL( [ - 'length' => '16', + 'length' => 16, 'fixed' => true, ], ); @@ -67,7 +69,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?UuidInte try { $uuid = Uuid::fromBytes($value); } catch (Throwable $e) { - throw ConversionException::conversionFailed($value, self::NAME); + throw ValueNotConvertible::new($value, self::NAME); } return $uuid; @@ -96,20 +98,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str // Ignore the exception and pass through. } - throw ConversionException::conversionFailed($value, self::NAME); + throw InvalidType::new($value, self::NAME, ['null', 'string', UuidInterface::class]); } - public function getName(): string - { - return self::NAME; - } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } - - public function getBindingType(): int + public function getBindingType(): ParameterType { return ParameterType::BINARY; } diff --git a/src/UuidType.php b/src/UuidType.php index 3ae95d2..f1828db 100644 --- a/src/UuidType.php +++ b/src/UuidType.php @@ -16,6 +16,8 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\GuidType; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; @@ -53,7 +55,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?UuidInte try { $uuid = Uuid::fromString($value); } catch (Throwable $e) { - throw ConversionException::conversionFailed($value, self::NAME); + throw ValueNotConvertible::new($value, self::NAME); } return $uuid; @@ -81,17 +83,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return (string) $value; } - throw ConversionException::conversionFailed($value, self::NAME); - } - - public function getName(): string - { - return self::NAME; - } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; + throw InvalidType::new($value, self::NAME, ['null', 'string', UuidInterface::class, Uuid::class]); } /** diff --git a/tests/UuidBinaryOrderedTimeTypeTest.php b/tests/UuidBinaryOrderedTimeTypeTest.php index 78b3e7e..7423cbd 100644 --- a/tests/UuidBinaryOrderedTimeTypeTest.php +++ b/tests/UuidBinaryOrderedTimeTypeTest.php @@ -4,6 +4,7 @@ namespace Ramsey\Uuid\Doctrine; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; @@ -44,11 +45,6 @@ private function getType(): Type return Type::getType('uuid_binary_ordered_time'); } - public function testGetName(): void - { - $this->assertSame('uuid_binary_ordered_time', $this->getType()->getName()); - } - public function testUuidConvertsToDatabaseValue(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); @@ -135,13 +131,8 @@ public function testGetGuidTypeDeclarationSQL(): void ); } - public function testRequiresSQLCommentHint(): void - { - $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform())); - } - public function testItReturnsAppropriateBindingType(): void { - $this->assertEquals(16, $this->getType()->getBindingType()); + $this->assertEquals(ParameterType::BINARY, $this->getType()->getBindingType()); } } diff --git a/tests/UuidBinaryTypeTest.php b/tests/UuidBinaryTypeTest.php index 2439722..4299a9f 100644 --- a/tests/UuidBinaryTypeTest.php +++ b/tests/UuidBinaryTypeTest.php @@ -4,6 +4,7 @@ namespace Ramsey\Uuid\Doctrine; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; @@ -120,11 +121,6 @@ public function testReturnValueIfUuid7ForPHPValue(): void $this->assertSame($uuid, $this->getType()->convertToPHPValue($uuid, $this->getPlatform())); } - public function testGetName(): void - { - $this->assertSame('uuid_binary', $this->getType()->getName()); - } - public function testGetGuidTypeDeclarationSQL(): void { $this->assertSame( @@ -133,13 +129,8 @@ public function testGetGuidTypeDeclarationSQL(): void ); } - public function testRequiresSQLCommentHint(): void - { - $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform())); - } - public function testItReturnsAppropriateBindingType(): void { - $this->assertEquals(16, $this->getType()->getBindingType()); + $this->assertEquals(ParameterType::BINARY, $this->getType()->getBindingType()); } } diff --git a/tests/UuidTypeTest.php b/tests/UuidTypeTest.php index d66160d..25e0ebd 100644 --- a/tests/UuidTypeTest.php +++ b/tests/UuidTypeTest.php @@ -125,11 +125,6 @@ public function testReturnValueIfUuidForPHPValue(): void $this->assertSame($uuid, $this->getType()->convertToPHPValue($uuid, $this->getPlatform())); } - public function testGetName(): void - { - $this->assertSame('uuid', $this->getType()->getName()); - } - public function testGetGuidTypeDeclarationSQL(): void { $this->assertSame( @@ -138,11 +133,6 @@ public function testGetGuidTypeDeclarationSQL(): void ); } - public function testRequiresSQLCommentHint(): void - { - $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform())); - } - public function testGetMappedDatabaseTypes(): void { $this->assertSame(['uuid'], $this->getType()->getMappedDatabaseTypes($this->getPlatform()));