From 88418b759f249a1a963ce29e30d01e55a06d5238 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 5 Feb 2024 23:30:43 +0100 Subject: [PATCH 1/5] Upgrade to doctrine/orm v3 & doctrine/dbal v4 --- composer.json | 8 +-- psalm-baseline.xml | 13 ----- psalm.xml | 1 - src/Types/DayOfWeekType.php | 34 +++---------- src/Types/DurationType.php | 24 +++------ src/Types/InstantType.php | 24 +++------ src/Types/LocalDateTimeType.php | 22 +++----- src/Types/LocalDateType.php | 22 +++----- src/Types/LocalTimeType.php | 22 +++----- src/Types/PeriodType.php | 24 +++------ tests/AbstractFunctionalTestCase.php | 20 ++++---- tests/Entity/KitchenSink.php | 72 +++++++-------------------- tests/Types/DayOfWeekTypeTest.php | 12 ++--- tests/Types/DurationTypeTest.php | 10 ++-- tests/Types/InstantTypeTest.php | 8 +-- tests/Types/LocalDateTimeTypeTest.php | 10 ++-- tests/Types/LocalDateTypeTest.php | 10 ++-- tests/Types/LocalTimeTypeTest.php | 10 ++-- tests/Types/PeriodTypeTest.php | 10 ++-- tests/TypesFunctionalTest.php | 18 +++---- 20 files changed, 122 insertions(+), 252 deletions(-) delete mode 100644 psalm-baseline.xml diff --git a/composer.json b/composer.json index 65f4c37..3e656b5 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ "license": "MIT", "require": { "brick/date-time": "~0.6.0", - "doctrine/dbal": "^2.7.0 || ^3.0", - "doctrine/orm": "^2.7.0", + "doctrine/dbal": "^4.0", + "doctrine/orm": "^3.0", "php": "^8.1" }, "require-dev": { @@ -20,8 +20,8 @@ "phpunit/phpunit": "^10.5", "php-coveralls/php-coveralls": "^2.4", "vimeo/psalm": "5.21.1", - "doctrine/annotations": "^1.0", - "guzzlehttp/guzzle": "^7.0" + "guzzlehttp/guzzle": "^7.0", + "symfony/cache": "^5.0 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index 4725a58..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - getVarcharTypeDeclarationSQL - - - - - getVarcharTypeDeclarationSQL - - - diff --git a/psalm.xml b/psalm.xml index 9d52591..f19428c 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,7 +5,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" - errorBaseline="psalm-baseline.xml" findUnusedBaselineEntry="true" findUnusedPsalmSuppress="true" findUnusedCode="false" diff --git a/src/Types/DayOfWeekType.php b/src/Types/DayOfWeekType.php index e78edda..f446599 100644 --- a/src/Types/DayOfWeekType.php +++ b/src/Types/DayOfWeekType.php @@ -6,7 +6,7 @@ use Brick\DateTime\DayOfWeek; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -17,17 +17,12 @@ */ final class DayOfWeekType extends Type { - public function getName(): string - { - return 'DayOfWeek'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getSmallIntTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?int { if ($value === null) { return null; @@ -37,37 +32,24 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int return $value->value; } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [DayOfWeek::class, 'null'] + static::class, + [DayOfWeek::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?DayOfWeek + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DayOfWeek { if ($value === null) { return null; } - if (is_int($value)) { - return DayOfWeek::from($value); - } - - throw ConversionException::conversionFailedInvalidType( - $value, - $this->getName(), - [DayOfWeek::class, 'null'] - ); + return DayOfWeek::from((int) $value); } - public function getBindingType(): int + public function getBindingType(): ParameterType { return ParameterType::INTEGER; } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/src/Types/DurationType.php b/src/Types/DurationType.php index a3475e0..de2af1c 100644 --- a/src/Types/DurationType.php +++ b/src/Types/DurationType.php @@ -6,7 +6,7 @@ use Brick\DateTime\Duration; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; /** @@ -16,21 +16,16 @@ */ final class DurationType extends Type { - public function getName(): string - { - return 'Duration'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { if (!isset($column['length'])) { $column['length'] = 64; } - return $platform->getVarcharTypeDeclarationSQL($column); + return $platform->getStringTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -40,14 +35,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return (string) $value; } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [Duration::class, 'null'] + static::class, + [Duration::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?Duration + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Duration { if ($value === null) { return null; @@ -55,9 +50,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?Duration return Duration::parse((string) $value); } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/src/Types/InstantType.php b/src/Types/InstantType.php index 8299257..90665de 100644 --- a/src/Types/InstantType.php +++ b/src/Types/InstantType.php @@ -6,7 +6,7 @@ use Brick\DateTime\Instant; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -17,17 +17,12 @@ */ final class InstantType extends Type { - public function getName(): string - { - return 'Instant'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getIntegerTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?int { if ($value === null) { return null; @@ -37,14 +32,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int return $value->getEpochSecond(); } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [Instant::class, 'null'] + static::class, + [Instant::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?Instant + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Instant { if ($value === null) { return null; @@ -53,13 +48,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?Instant return Instant::of((int) $value); } - public function getBindingType(): int + public function getBindingType(): ParameterType { return ParameterType::INTEGER; } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/src/Types/LocalDateTimeType.php b/src/Types/LocalDateTimeType.php index 8f888bb..febc2c9 100644 --- a/src/Types/LocalDateTimeType.php +++ b/src/Types/LocalDateTimeType.php @@ -5,7 +5,7 @@ namespace Brick\DateTime\Doctrine\Types; use Brick\DateTime\LocalDateTime; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -16,17 +16,12 @@ */ final class LocalDateTimeType extends Type { - public function getName(): string - { - return 'LocalDateTime'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getDateTimeTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -42,14 +37,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return $stringValue; } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [LocalDateTime::class, 'null'] + static::class, + [LocalDateTime::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?LocalDateTime + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?LocalDateTime { if ($value === null) { return null; @@ -59,9 +54,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?LocalDat return LocalDateTime::parse($value); } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/src/Types/LocalDateType.php b/src/Types/LocalDateType.php index 642ecb7..0e3fafc 100644 --- a/src/Types/LocalDateType.php +++ b/src/Types/LocalDateType.php @@ -5,7 +5,7 @@ namespace Brick\DateTime\Doctrine\Types; use Brick\DateTime\LocalDate; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -16,17 +16,12 @@ */ final class LocalDateType extends Type { - public function getName(): string - { - return 'LocalDate'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getDateTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -36,14 +31,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return (string) $value; } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [LocalDate::class, 'null'] + static::class, + [LocalDate::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?LocalDate + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?LocalDate { if ($value === null) { return null; @@ -51,9 +46,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?LocalDat return LocalDate::parse((string) $value); } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/src/Types/LocalTimeType.php b/src/Types/LocalTimeType.php index 0fe593d..338ed5b 100644 --- a/src/Types/LocalTimeType.php +++ b/src/Types/LocalTimeType.php @@ -5,7 +5,7 @@ namespace Brick\DateTime\Doctrine\Types; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -16,17 +16,12 @@ */ final class LocalTimeType extends Type { - public function getName(): string - { - return 'LocalTime'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getTimeTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -42,14 +37,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return $stringValue; } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [LocalTime::class, 'null'] + static::class, + [LocalTime::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?LocalTime + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?LocalTime { if ($value === null) { return null; @@ -57,9 +52,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?LocalTim return LocalTime::parse((string) $value); } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/src/Types/PeriodType.php b/src/Types/PeriodType.php index 153e856..f317282 100644 --- a/src/Types/PeriodType.php +++ b/src/Types/PeriodType.php @@ -6,7 +6,7 @@ use Brick\DateTime\Period; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; /** @@ -16,21 +16,16 @@ */ final class PeriodType extends Type { - public function getName(): string - { - return 'Period'; - } - public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { if (!isset($column['length'])) { $column['length'] = 64; } - return $platform->getVarcharTypeDeclarationSQL($column); + return $platform->getStringTypeDeclarationSQL($column); } - public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -40,14 +35,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return (string) $value; } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, - $this->getName(), - [Period::class, 'null'] + static::class, + [Period::class, 'null'], ); } - public function convertToPHPValue($value, AbstractPlatform $platform): ?Period + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Period { if ($value === null) { return null; @@ -55,9 +50,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?Period return Period::parse((string) $value); } - - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } } diff --git a/tests/AbstractFunctionalTestCase.php b/tests/AbstractFunctionalTestCase.php index 0add612..613d69b 100644 --- a/tests/AbstractFunctionalTestCase.php +++ b/tests/AbstractFunctionalTestCase.php @@ -7,33 +7,31 @@ use Brick\DateTime\Doctrine\Tests\Entity\KitchenSink; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Tools\DsnParser; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\ORMSetup; use PHPUnit\Framework\TestCase; abstract class AbstractFunctionalTestCase extends TestCase { final protected static function createConnection(): Connection { - return DriverManager::getConnection(['url' => 'sqlite:///:memory:']); + $dsnParser = new DsnParser(['sqlite' => 'pdo_sqlite']); + + return DriverManager::getConnection( + $dsnParser->parse('sqlite:///:memory:'), + ); } final protected static function createEntityManager(Connection $connection): EntityManager { - return EntityManager::create($connection, self::createConfiguration()); + return new EntityManager($connection, self::createConfiguration()); } private static function createConfiguration(): Configuration { - $config = new Configuration(); - - $driverImpl = $config->newDefaultAnnotationDriver([__DIR__ . '/tests/Entity'], false); - $config->setMetadataDriverImpl($driverImpl); - - $config->setProxyDir(sys_get_temp_dir()); - $config->setProxyNamespace('Brick\DateTime\Doctrine\Tests\Proxy'); - - return $config; + return ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/tests/Entity']); } final protected static function truncateEntityTable(EntityManager $em): void diff --git a/tests/Entity/KitchenSink.php b/tests/Entity/KitchenSink.php index de35716..c8036ae 100644 --- a/tests/Entity/KitchenSink.php +++ b/tests/Entity/KitchenSink.php @@ -13,66 +13,32 @@ use Brick\DateTime\Period; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class KitchenSink { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - * - * @var int - */ - public $id; + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] + public int $id; - /** - * @ORM\Column(type="DayOfWeek", nullable=true) - * - * @var DayOfWeek|null - */ - public $dayOfWeek = null; + #[ORM\Column(type: 'DayOfWeek', nullable: true)] + public ?DayOfWeek $dayOfWeek = null; - /** - * @ORM\Column(type="Instant", nullable=true) - * - * @var Instant|null - */ - public $instant = null; + #[ORM\Column(type: 'Instant', nullable: true)] + public ?Instant $instant = null; - /** - * @ORM\Column(type="LocalDate", nullable=true) - * - * @var LocalDate|null - */ - public $localDate = null; + #[ORM\Column(type: 'LocalDate', nullable: true)] + public ?LocalDate $localDate = null; - /** - * @ORM\Column(type="LocalTime", nullable=true) - * - * @var LocalTime|null - */ - public $localTime = null; + #[ORM\Column(type: 'LocalTime', nullable: true)] + public ?LocalTime $localTime = null; - /** - * @ORM\Column(type="LocalDateTime", nullable=true) - * - * @var LocalDateTime|null - */ - public $localDateTime = null; + #[ORM\Column(type: 'LocalDateTime', nullable: true)] + public ?LocalDateTime $localDateTime = null; - /** - * @ORM\Column(type="Duration", nullable=true) - * - * @var Duration|null - */ - public $duration = null; + #[ORM\Column(type: 'Duration', nullable: true)] + public ?Duration $duration = null; - /** - * @ORM\Column(type="Period", nullable=true) - * - * @var Period|null - */ - public $period = null; + #[ORM\Column(type: 'Period', nullable: true)] + public ?Period $period = null; } diff --git a/tests/Types/DayOfWeekTypeTest.php b/tests/Types/DayOfWeekTypeTest.php index 53f0aa3..9a6584d 100644 --- a/tests/Types/DayOfWeekTypeTest.php +++ b/tests/Types/DayOfWeekTypeTest.php @@ -8,7 +8,7 @@ use Brick\DateTime\Doctrine\Types\DayOfWeekType; use Brick\DateTime\LocalDate; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ private function getDayOfWeekType(): DayOfWeekType public function testConvertToDatabaseValue(?DayOfWeek $value, ?int $expectedValue): void { $type = $this->getDayOfWeekType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -55,7 +55,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getDayOfWeekType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -77,7 +77,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?int $expectedDayOfWeekValue): void { $type = $this->getDayOfWeekType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedDayOfWeekValue === null) { self::assertNull($actualValue); @@ -109,7 +109,7 @@ public function testConvertToPHPValueWithInvalidValue($value, string $expectedEx $type = $this->getDayOfWeekType(); $this->expectException($expectedExceptionClass); - $type->convertToPHPValue($value, new SqlitePlatform()); + $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array @@ -117,8 +117,6 @@ public static function providerConvertToPHPValueWithInvalidValue(): array return [ [0, ValueError::class], [8, ValueError::class], - ['1', ConversionException::class], - ['2', ConversionException::class], ]; } } diff --git a/tests/Types/DurationTypeTest.php b/tests/Types/DurationTypeTest.php index ccefb40..3884fd8 100644 --- a/tests/Types/DurationTypeTest.php +++ b/tests/Types/DurationTypeTest.php @@ -9,7 +9,7 @@ use Brick\DateTime\LocalDate; use Brick\DateTime\Duration; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ private function getDurationType(): DurationType public function testConvertToDatabaseValue(?Duration $value, ?string $expectedValue): void { $type = $this->getDurationType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -49,7 +49,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getDurationType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -71,7 +71,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?string $expectedDurationString): void { $type = $this->getDurationType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedDurationString === null) { self::assertNull($actualValue); @@ -97,7 +97,7 @@ public function testConvertToPHPValueWithInvalidValue($value, string $expectedEx $type = $this->getDurationType(); $this->expectException($expectedExceptionClass); - $type->convertToPHPValue($value, new SqlitePlatform()); + $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array diff --git a/tests/Types/InstantTypeTest.php b/tests/Types/InstantTypeTest.php index a73e305..0e944bb 100644 --- a/tests/Types/InstantTypeTest.php +++ b/tests/Types/InstantTypeTest.php @@ -8,7 +8,7 @@ use Brick\DateTime\Doctrine\Types\InstantType; use Brick\DateTime\LocalDate; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -27,7 +27,7 @@ private function getInstantType(): InstantType public function testConvertToDatabaseValue(?Instant $value, ?int $expectedValue): void { $type = $this->getInstantType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -49,7 +49,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getInstantType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -71,7 +71,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?int $expectedEpochSecond): void { $type = $this->getInstantType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedEpochSecond === null) { self::assertNull($actualValue); diff --git a/tests/Types/LocalDateTimeTypeTest.php b/tests/Types/LocalDateTimeTypeTest.php index de7322f..2ba5b2a 100644 --- a/tests/Types/LocalDateTimeTypeTest.php +++ b/tests/Types/LocalDateTimeTypeTest.php @@ -9,7 +9,7 @@ use Brick\DateTime\LocalDate; use Brick\DateTime\LocalDateTime; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ private function getLocalDateTimeType(): LocalDateTimeType public function testConvertToDatabaseValue(?LocalDateTime $value, ?string $expectedValue): void { $type = $this->getLocalDateTimeType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -51,7 +51,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getLocalDateTimeType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -74,7 +74,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?string $expectedLocalDateTimeString): void { $type = $this->getLocalDateTimeType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedLocalDateTimeString === null) { self::assertNull($actualValue); @@ -103,7 +103,7 @@ public function testConvertToPHPValueWithInvalidValue($value, string $expectedEx $type = $this->getLocalDateTimeType(); $this->expectException($expectedExceptionClass); - $type->convertToPHPValue($value, new SqlitePlatform()); + $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array diff --git a/tests/Types/LocalDateTypeTest.php b/tests/Types/LocalDateTypeTest.php index 50d9d35..459a323 100644 --- a/tests/Types/LocalDateTypeTest.php +++ b/tests/Types/LocalDateTypeTest.php @@ -9,7 +9,7 @@ use Brick\DateTime\LocalDate; use Brick\DateTime\LocalDateTime; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ private function getLocalDateType(): LocalDateType public function testConvertToDatabaseValue(?LocalDate $value, ?string $expectedValue): void { $type = $this->getLocalDateType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -49,7 +49,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getLocalDateType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -71,7 +71,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?string $expectedLocalDateString): void { $type = $this->getLocalDateType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedLocalDateString === null) { self::assertNull($actualValue); @@ -97,7 +97,7 @@ public function testConvertToPHPValueWithInvalidValue($value, string $expectedEx $type = $this->getLocalDateType(); $this->expectException($expectedExceptionClass); - $type->convertToPHPValue($value, new SqlitePlatform()); + $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array diff --git a/tests/Types/LocalTimeTypeTest.php b/tests/Types/LocalTimeTypeTest.php index 08b09ce..76cba60 100644 --- a/tests/Types/LocalTimeTypeTest.php +++ b/tests/Types/LocalTimeTypeTest.php @@ -9,7 +9,7 @@ use Brick\DateTime\LocalDate; use Brick\DateTime\LocalTime; use Brick\DateTime\LocalDateTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ private function getLocalTimeType(): LocalTimeType public function testConvertToDatabaseValue(?LocalTime $value, ?string $expectedValue): void { $type = $this->getLocalTimeType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -51,7 +51,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getLocalTimeType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -73,7 +73,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?string $expectedLocalTimeString): void { $type = $this->getLocalTimeType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedLocalTimeString === null) { self::assertNull($actualValue); @@ -100,7 +100,7 @@ public function testConvertToPHPValueWithInvalidValue($value, string $expectedEx $type = $this->getLocalTimeType(); $this->expectException($expectedExceptionClass); - $type->convertToPHPValue($value, new SqlitePlatform()); + $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array diff --git a/tests/Types/PeriodTypeTest.php b/tests/Types/PeriodTypeTest.php index 68a1bb8..13d5ec3 100644 --- a/tests/Types/PeriodTypeTest.php +++ b/tests/Types/PeriodTypeTest.php @@ -9,7 +9,7 @@ use Brick\DateTime\LocalDate; use Brick\DateTime\Period; use Brick\DateTime\LocalTime; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ private function getPeriodType(): PeriodType public function testConvertToDatabaseValue(?Period $value, ?string $expectedValue): void { $type = $this->getPeriodType(); - $actualValue = $type->convertToDatabaseValue($value, new SqlitePlatform()); + $actualValue = $type->convertToDatabaseValue($value, new SQLitePlatform()); self::assertSame($expectedValue, $actualValue); } @@ -49,7 +49,7 @@ public function testConvertToDatabaseValueWithInvalidValue($value): void $type = $this->getPeriodType(); $this->expectException(ConversionException::class); - $type->convertToDatabaseValue($value, new SqlitePlatform()); + $type->convertToDatabaseValue($value, new SQLitePlatform()); } public static function providerConvertToDatabaseValueWithInvalidValue(): array @@ -71,7 +71,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array public function testConvertToPHPValue($value, ?string $expectedPeriodString): void { $type = $this->getPeriodType(); - $actualValue = $type->convertToPHPValue($value, new SqlitePlatform()); + $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); if ($expectedPeriodString === null) { self::assertNull($actualValue); @@ -97,7 +97,7 @@ public function testConvertToPHPValueWithInvalidValue($value, string $expectedEx $type = $this->getPeriodType(); $this->expectException($expectedExceptionClass); - $type->convertToPHPValue($value, new SqlitePlatform()); + $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array diff --git a/tests/TypesFunctionalTest.php b/tests/TypesFunctionalTest.php index 04e102c..d34a413 100644 --- a/tests/TypesFunctionalTest.php +++ b/tests/TypesFunctionalTest.php @@ -29,15 +29,15 @@ public function testCreateSchema(): Connection self::assertCount(1, $sql); $sql = $sql[0]; - self::assertStringContainsString('dayOfWeek SMALLINT DEFAULT NULL --(DC2Type:DayOfWeek)', $sql); - self::assertStringContainsString('instant INTEGER DEFAULT NULL --(DC2Type:Instant)', $sql); - self::assertStringContainsString('localDate DATE DEFAULT NULL --(DC2Type:LocalDate)', $sql); - self::assertStringContainsString('localTime TIME DEFAULT NULL --(DC2Type:LocalTime)', $sql); - self::assertStringContainsString('localDateTime DATETIME DEFAULT NULL --(DC2Type:LocalDateTime)', $sql); - self::assertStringContainsString('duration VARCHAR(64) DEFAULT NULL --(DC2Type:Duration)', $sql); - self::assertStringContainsString('period VARCHAR(64) DEFAULT NULL --(DC2Type:Period)', $sql); - - $connection->exec($sql); + self::assertStringContainsString('dayOfWeek SMALLINT DEFAULT NULL', $sql); + self::assertStringContainsString('instant INTEGER DEFAULT NULL', $sql); + self::assertStringContainsString('localDate DATE DEFAULT NULL', $sql); + self::assertStringContainsString('localTime TIME DEFAULT NULL', $sql); + self::assertStringContainsString('localDateTime DATETIME DEFAULT NULL', $sql); + self::assertStringContainsString('duration VARCHAR(64) DEFAULT NULL', $sql); + self::assertStringContainsString('period VARCHAR(64) DEFAULT NULL', $sql); + + $connection->executeStatement($sql); return $connection; } From aeacec16fccf022bd673bcf2e436079a5dc23d1b Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 5 Feb 2024 23:51:05 +0100 Subject: [PATCH 2/5] Migrate to PHPUnit attributes --- tests/Types/DayOfWeekTypeTest.php | 17 +++++------------ tests/Types/DurationTypeTest.php | 17 +++++------------ tests/Types/InstantTypeTest.php | 13 ++++--------- tests/Types/LocalDateTimeTypeTest.php | 17 +++++------------ tests/Types/LocalDateTypeTest.php | 17 +++++------------ tests/Types/LocalTimeTypeTest.php | 17 +++++------------ tests/Types/PeriodTypeTest.php | 17 +++++------------ tests/TypesFunctionalTest.php | 17 +++++------------ 8 files changed, 39 insertions(+), 93 deletions(-) diff --git a/tests/Types/DayOfWeekTypeTest.php b/tests/Types/DayOfWeekTypeTest.php index 9a6584d..1eca2b0 100644 --- a/tests/Types/DayOfWeekTypeTest.php +++ b/tests/Types/DayOfWeekTypeTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; use ValueError; @@ -22,9 +23,7 @@ private function getDayOfWeekType(): DayOfWeekType return Type::getType('DayOfWeek'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?DayOfWeek $value, ?int $expectedValue): void { $type = $this->getDayOfWeekType(); @@ -47,9 +46,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getDayOfWeekType(); @@ -71,9 +68,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?int $expectedDayOfWeekValue): void { $type = $this->getDayOfWeekType(); @@ -101,9 +96,7 @@ public static function providerConvertToPHPValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValueWithInvalidValue - */ + #[DataProvider('providerConvertToPHPValueWithInvalidValue')] public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void { $type = $this->getDayOfWeekType(); diff --git a/tests/Types/DurationTypeTest.php b/tests/Types/DurationTypeTest.php index 3884fd8..c01bcd0 100644 --- a/tests/Types/DurationTypeTest.php +++ b/tests/Types/DurationTypeTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -22,9 +23,7 @@ private function getDurationType(): DurationType return Type::getType('Duration'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?Duration $value, ?string $expectedValue): void { $type = $this->getDurationType(); @@ -41,9 +40,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getDurationType(); @@ -65,9 +62,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?string $expectedDurationString): void { $type = $this->getDurationType(); @@ -89,9 +84,7 @@ public static function providerConvertToPHPValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValueWithInvalidValue - */ + #[DataProvider('providerConvertToPHPValueWithInvalidValue')] public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void { $type = $this->getDurationType(); diff --git a/tests/Types/InstantTypeTest.php b/tests/Types/InstantTypeTest.php index 0e944bb..be180d3 100644 --- a/tests/Types/InstantTypeTest.php +++ b/tests/Types/InstantTypeTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -21,9 +22,7 @@ private function getInstantType(): InstantType return Type::getType('Instant'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?Instant $value, ?int $expectedValue): void { $type = $this->getInstantType(); @@ -41,9 +40,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getInstantType(); @@ -65,9 +62,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?int $expectedEpochSecond): void { $type = $this->getInstantType(); diff --git a/tests/Types/LocalDateTimeTypeTest.php b/tests/Types/LocalDateTimeTypeTest.php index 2ba5b2a..dcc0043 100644 --- a/tests/Types/LocalDateTimeTypeTest.php +++ b/tests/Types/LocalDateTimeTypeTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -22,9 +23,7 @@ private function getLocalDateTimeType(): LocalDateTimeType return Type::getType('LocalDateTime'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?LocalDateTime $value, ?string $expectedValue): void { $type = $this->getLocalDateTimeType(); @@ -43,9 +42,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getLocalDateTimeType(); @@ -68,9 +65,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?string $expectedLocalDateTimeString): void { $type = $this->getLocalDateTimeType(); @@ -95,9 +90,7 @@ public static function providerConvertToPHPValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValueWithInvalidValue - */ + #[DataProvider('providerConvertToPHPValueWithInvalidValue')] public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void { $type = $this->getLocalDateTimeType(); diff --git a/tests/Types/LocalDateTypeTest.php b/tests/Types/LocalDateTypeTest.php index 459a323..7a59709 100644 --- a/tests/Types/LocalDateTypeTest.php +++ b/tests/Types/LocalDateTypeTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -22,9 +23,7 @@ private function getLocalDateType(): LocalDateType return Type::getType('LocalDate'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?LocalDate $value, ?string $expectedValue): void { $type = $this->getLocalDateType(); @@ -41,9 +40,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getLocalDateType(); @@ -65,9 +62,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?string $expectedLocalDateString): void { $type = $this->getLocalDateType(); @@ -89,9 +84,7 @@ public static function providerConvertToPHPValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValueWithInvalidValue - */ + #[DataProvider('providerConvertToPHPValueWithInvalidValue')] public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void { $type = $this->getLocalDateType(); diff --git a/tests/Types/LocalTimeTypeTest.php b/tests/Types/LocalTimeTypeTest.php index 76cba60..c2cc2dd 100644 --- a/tests/Types/LocalTimeTypeTest.php +++ b/tests/Types/LocalTimeTypeTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -22,9 +23,7 @@ private function getLocalTimeType(): LocalTimeType return Type::getType('LocalTime'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?LocalTime $value, ?string $expectedValue): void { $type = $this->getLocalTimeType(); @@ -43,9 +42,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getLocalTimeType(); @@ -67,9 +64,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?string $expectedLocalTimeString): void { $type = $this->getLocalTimeType(); @@ -92,9 +87,7 @@ public static function providerConvertToPHPValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValueWithInvalidValue - */ + #[DataProvider('providerConvertToPHPValueWithInvalidValue')] public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void { $type = $this->getLocalTimeType(); diff --git a/tests/Types/PeriodTypeTest.php b/tests/Types/PeriodTypeTest.php index 13d5ec3..54aebf4 100644 --- a/tests/Types/PeriodTypeTest.php +++ b/tests/Types/PeriodTypeTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -22,9 +23,7 @@ private function getPeriodType(): PeriodType return Type::getType('Period'); } - /** - * @dataProvider providerConvertToDatabaseValue - */ + #[DataProvider('providerConvertToDatabaseValue')] public function testConvertToDatabaseValue(?Period $value, ?string $expectedValue): void { $type = $this->getPeriodType(); @@ -41,9 +40,7 @@ public static function providerConvertToDatabaseValue(): array ]; } - /** - * @dataProvider providerConvertToDatabaseValueWithInvalidValue - */ + #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] public function testConvertToDatabaseValueWithInvalidValue($value): void { $type = $this->getPeriodType(); @@ -65,9 +62,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValue - */ + #[DataProvider('providerConvertToPHPValue')] public function testConvertToPHPValue($value, ?string $expectedPeriodString): void { $type = $this->getPeriodType(); @@ -89,9 +84,7 @@ public static function providerConvertToPHPValue(): array ]; } - /** - * @dataProvider providerConvertToPHPValueWithInvalidValue - */ + #[DataProvider('providerConvertToPHPValueWithInvalidValue')] public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void { $type = $this->getPeriodType(); diff --git a/tests/TypesFunctionalTest.php b/tests/TypesFunctionalTest.php index d34a413..9f1604f 100644 --- a/tests/TypesFunctionalTest.php +++ b/tests/TypesFunctionalTest.php @@ -14,6 +14,7 @@ use Brick\DateTime\Period; use Doctrine\DBAL\Connection; use Doctrine\ORM\Tools\SchemaTool; +use PHPUnit\Framework\Attributes\Depends; class TypesFunctionalTest extends AbstractFunctionalTestCase { @@ -42,9 +43,7 @@ public function testCreateSchema(): Connection return $connection; } - /** - * @depends testCreateSchema - */ + #[Depends('testCreateSchema')] public function testSaveNull(Connection $connection): Connection { $em = self::createEntityManager($connection); @@ -61,9 +60,7 @@ public function testSaveNull(Connection $connection): Connection return $connection; } - /** - * @depends testSaveNull - */ + #[Depends('testSaveNull')] public function testLoadNull(Connection $connection): void { $em = self::createEntityManager($connection); @@ -81,9 +78,7 @@ public function testLoadNull(Connection $connection): void self::assertNull($entity->period); } - /** - * @depends testCreateSchema - */ + #[Depends('testCreateSchema')] public function testSaveValues(Connection $connection): Connection { $em = self::createEntityManager($connection); @@ -108,9 +103,7 @@ public function testSaveValues(Connection $connection): Connection return $connection; } - /** - * @depends testSaveValues - */ + #[Depends('testSaveValues')] public function testLoadValues(Connection $connection): void { $em = self::createEntityManager($connection); From 1e12f8124dfd9d8762fef1c683ff4bd4acb080ee Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 5 Feb 2024 23:55:16 +0100 Subject: [PATCH 3/5] Mixed types --- tests/Types/DayOfWeekTypeTest.php | 6 +++--- tests/Types/DurationTypeTest.php | 6 +++--- tests/Types/InstantTypeTest.php | 4 ++-- tests/Types/LocalDateTimeTypeTest.php | 6 +++--- tests/Types/LocalDateTypeTest.php | 6 +++--- tests/Types/LocalTimeTypeTest.php | 6 +++--- tests/Types/PeriodTypeTest.php | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/Types/DayOfWeekTypeTest.php b/tests/Types/DayOfWeekTypeTest.php index 1eca2b0..5097b31 100644 --- a/tests/Types/DayOfWeekTypeTest.php +++ b/tests/Types/DayOfWeekTypeTest.php @@ -47,7 +47,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getDayOfWeekType(); @@ -69,7 +69,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?int $expectedDayOfWeekValue): void + public function testConvertToPHPValue(mixed $value, ?int $expectedDayOfWeekValue): void { $type = $this->getDayOfWeekType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); @@ -97,7 +97,7 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void { $type = $this->getDayOfWeekType(); diff --git a/tests/Types/DurationTypeTest.php b/tests/Types/DurationTypeTest.php index c01bcd0..a73881f 100644 --- a/tests/Types/DurationTypeTest.php +++ b/tests/Types/DurationTypeTest.php @@ -41,7 +41,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getDurationType(); @@ -63,7 +63,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?string $expectedDurationString): void + public function testConvertToPHPValue(mixed $value, ?string $expectedDurationString): void { $type = $this->getDurationType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); @@ -85,7 +85,7 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void { $type = $this->getDurationType(); diff --git a/tests/Types/InstantTypeTest.php b/tests/Types/InstantTypeTest.php index be180d3..9770896 100644 --- a/tests/Types/InstantTypeTest.php +++ b/tests/Types/InstantTypeTest.php @@ -41,7 +41,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getInstantType(); @@ -63,7 +63,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?int $expectedEpochSecond): void + public function testConvertToPHPValue(mixed $value, ?int $expectedEpochSecond): void { $type = $this->getInstantType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); diff --git a/tests/Types/LocalDateTimeTypeTest.php b/tests/Types/LocalDateTimeTypeTest.php index dcc0043..3a037cc 100644 --- a/tests/Types/LocalDateTimeTypeTest.php +++ b/tests/Types/LocalDateTimeTypeTest.php @@ -43,7 +43,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getLocalDateTimeType(); @@ -66,7 +66,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?string $expectedLocalDateTimeString): void + public function testConvertToPHPValue(mixed $value, ?string $expectedLocalDateTimeString): void { $type = $this->getLocalDateTimeType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); @@ -91,7 +91,7 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void { $type = $this->getLocalDateTimeType(); diff --git a/tests/Types/LocalDateTypeTest.php b/tests/Types/LocalDateTypeTest.php index 7a59709..ad7b885 100644 --- a/tests/Types/LocalDateTypeTest.php +++ b/tests/Types/LocalDateTypeTest.php @@ -41,7 +41,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getLocalDateType(); @@ -63,7 +63,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?string $expectedLocalDateString): void + public function testConvertToPHPValue(mixed $value, ?string $expectedLocalDateString): void { $type = $this->getLocalDateType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); @@ -85,7 +85,7 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void { $type = $this->getLocalDateType(); diff --git a/tests/Types/LocalTimeTypeTest.php b/tests/Types/LocalTimeTypeTest.php index c2cc2dd..ce9ebd9 100644 --- a/tests/Types/LocalTimeTypeTest.php +++ b/tests/Types/LocalTimeTypeTest.php @@ -43,7 +43,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getLocalTimeType(); @@ -65,7 +65,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?string $expectedLocalTimeString): void + public function testConvertToPHPValue(mixed $value, ?string $expectedLocalTimeString): void { $type = $this->getLocalTimeType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); @@ -88,7 +88,7 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void { $type = $this->getLocalTimeType(); diff --git a/tests/Types/PeriodTypeTest.php b/tests/Types/PeriodTypeTest.php index 54aebf4..507d27c 100644 --- a/tests/Types/PeriodTypeTest.php +++ b/tests/Types/PeriodTypeTest.php @@ -41,7 +41,7 @@ public static function providerConvertToDatabaseValue(): array } #[DataProvider('providerConvertToDatabaseValueWithInvalidValue')] - public function testConvertToDatabaseValueWithInvalidValue($value): void + public function testConvertToDatabaseValueWithInvalidValue(mixed $value): void { $type = $this->getPeriodType(); @@ -63,7 +63,7 @@ public static function providerConvertToDatabaseValueWithInvalidValue(): array } #[DataProvider('providerConvertToPHPValue')] - public function testConvertToPHPValue($value, ?string $expectedPeriodString): void + public function testConvertToPHPValue(mixed $value, ?string $expectedPeriodString): void { $type = $this->getPeriodType(); $actualValue = $type->convertToPHPValue($value, new SQLitePlatform()); @@ -85,7 +85,7 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue($value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void { $type = $this->getPeriodType(); From eaae7309047cbcf95d2aa0f7d47bb5930d24e5c8 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 6 Feb 2024 00:00:06 +0100 Subject: [PATCH 4/5] Add extra tests to cover all edge cases of times --- tests/Types/LocalDateTimeTypeTest.php | 3 ++- tests/Types/LocalTimeTypeTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Types/LocalDateTimeTypeTest.php b/tests/Types/LocalDateTimeTypeTest.php index 3a037cc..65fd794 100644 --- a/tests/Types/LocalDateTimeTypeTest.php +++ b/tests/Types/LocalDateTimeTypeTest.php @@ -38,7 +38,8 @@ public static function providerConvertToDatabaseValue(): array [null, null], [LocalDateTime::of(2021, 4, 17, 9, 2), '2021-04-17 09:02:00'], [LocalDateTime::of(2021, 4, 17, 9, 2, 7), '2021-04-17 09:02:07'], - [LocalDateTime::of(2021, 4, 17, 9, 2, 0, 7000000), '2021-04-17 09:02:00.007'], + [LocalDateTime::of(2021, 4, 17, 9, 2, 0, 7_000_000), '2021-04-17 09:02:00.007'], + [LocalDateTime::of(2021, 4, 17, 9, 2, 1, 7_000_000), '2021-04-17 09:02:01.007'], ]; } diff --git a/tests/Types/LocalTimeTypeTest.php b/tests/Types/LocalTimeTypeTest.php index ce9ebd9..71e6df7 100644 --- a/tests/Types/LocalTimeTypeTest.php +++ b/tests/Types/LocalTimeTypeTest.php @@ -38,7 +38,8 @@ public static function providerConvertToDatabaseValue(): array [null, null], [LocalTime::of(9, 2), '09:02:00'], [LocalTime::of(10, 31, 1), '10:31:01'], - [LocalTime::of(10, 31, 1, 7000000), '10:31:01.007'], + [LocalTime::of(10, 31, 0, 7_000_000), '10:31:00.007'], + [LocalTime::of(10, 31, 1, 7_000_000), '10:31:01.007'], ]; } From 1577e2f74a80c88f02978bc18aba209c376a47ff Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 6 Feb 2024 23:56:35 +0100 Subject: [PATCH 5/5] Throw ConversionException in convertToPHPValue() --- src/Types/DayOfWeekType.php | 13 ++++++++++++- src/Types/DurationType.php | 13 ++++++++++++- src/Types/LocalDateTimeType.php | 13 ++++++++++++- src/Types/LocalDateType.php | 13 ++++++++++++- src/Types/LocalTimeType.php | 13 ++++++++++++- src/Types/PeriodType.php | 13 ++++++++++++- tests/Types/DayOfWeekTypeTest.php | 10 +++++----- tests/Types/DurationTypeTest.php | 12 ++++++------ tests/Types/LocalDateTimeTypeTest.php | 14 +++++++------- tests/Types/LocalDateTypeTest.php | 12 ++++++------ tests/Types/LocalTimeTypeTest.php | 12 ++++++------ tests/Types/PeriodTypeTest.php | 12 ++++++------ 12 files changed, 108 insertions(+), 42 deletions(-) diff --git a/src/Types/DayOfWeekType.php b/src/Types/DayOfWeekType.php index f446599..45ae4bf 100644 --- a/src/Types/DayOfWeekType.php +++ b/src/Types/DayOfWeekType.php @@ -7,8 +7,10 @@ use Brick\DateTime\DayOfWeek; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; +use ValueError; /** * Doctrine type for DayOfWeek. @@ -45,7 +47,16 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da return null; } - return DayOfWeek::from((int) $value); + try { + return DayOfWeek::from((int) $value); + } catch (ValueError $e) { + throw ValueNotConvertible::new( + $value, + DayOfWeek::class, + $e->getMessage(), + $e, + ); + } } public function getBindingType(): ParameterType diff --git a/src/Types/DurationType.php b/src/Types/DurationType.php index de2af1c..5477082 100644 --- a/src/Types/DurationType.php +++ b/src/Types/DurationType.php @@ -4,9 +4,11 @@ namespace Brick\DateTime\Doctrine\Types; +use Brick\DateTime\DateTimeException; use Brick\DateTime\Duration; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; /** @@ -48,6 +50,15 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Du return null; } - return Duration::parse((string) $value); + try { + return Duration::parse((string) $value); + } catch (DateTimeException $e) { + throw ValueNotConvertible::new( + $value, + Duration::class, + $e->getMessage(), + $e, + ); + } } } diff --git a/src/Types/LocalDateTimeType.php b/src/Types/LocalDateTimeType.php index febc2c9..8d55eea 100644 --- a/src/Types/LocalDateTimeType.php +++ b/src/Types/LocalDateTimeType.php @@ -4,8 +4,10 @@ namespace Brick\DateTime\Doctrine\Types; +use Brick\DateTime\DateTimeException; use Brick\DateTime\LocalDateTime; use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -52,6 +54,15 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Lo $value = str_replace(' ', 'T', (string) $value); - return LocalDateTime::parse($value); + try { + return LocalDateTime::parse($value); + } catch (DateTimeException $e) { + throw ValueNotConvertible::new( + $value, + LocalDateTime::class, + $e->getMessage(), + $e, + ); + } } } diff --git a/src/Types/LocalDateType.php b/src/Types/LocalDateType.php index 0e3fafc..d8d0a5d 100644 --- a/src/Types/LocalDateType.php +++ b/src/Types/LocalDateType.php @@ -4,8 +4,10 @@ namespace Brick\DateTime\Doctrine\Types; +use Brick\DateTime\DateTimeException; use Brick\DateTime\LocalDate; use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -44,6 +46,15 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Lo return null; } - return LocalDate::parse((string) $value); + try { + return LocalDate::parse((string) $value); + } catch (DateTimeException $e) { + throw ValueNotConvertible::new( + $value, + LocalDate::class, + $e->getMessage(), + $e, + ); + } } } diff --git a/src/Types/LocalTimeType.php b/src/Types/LocalTimeType.php index 338ed5b..a5fe911 100644 --- a/src/Types/LocalTimeType.php +++ b/src/Types/LocalTimeType.php @@ -4,8 +4,10 @@ namespace Brick\DateTime\Doctrine\Types; +use Brick\DateTime\DateTimeException; use Brick\DateTime\LocalTime; use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -50,6 +52,15 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Lo return null; } - return LocalTime::parse((string) $value); + try { + return LocalTime::parse((string) $value); + } catch (DateTimeException $e) { + throw ValueNotConvertible::new( + $value, + LocalTime::class, + $e->getMessage(), + $e, + ); + } } } diff --git a/src/Types/PeriodType.php b/src/Types/PeriodType.php index f317282..295defd 100644 --- a/src/Types/PeriodType.php +++ b/src/Types/PeriodType.php @@ -4,9 +4,11 @@ namespace Brick\DateTime\Doctrine\Types; +use Brick\DateTime\DateTimeException; use Brick\DateTime\Period; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; /** @@ -48,6 +50,15 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Pe return null; } - return Period::parse((string) $value); + try { + return Period::parse((string) $value); + } catch (DateTimeException $e) { + throw ValueNotConvertible::new( + $value, + Period::class, + $e->getMessage(), + $e, + ); + } } } diff --git a/tests/Types/DayOfWeekTypeTest.php b/tests/Types/DayOfWeekTypeTest.php index 5097b31..6c21106 100644 --- a/tests/Types/DayOfWeekTypeTest.php +++ b/tests/Types/DayOfWeekTypeTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; -use ValueError; class DayOfWeekTypeTest extends TestCase { @@ -97,19 +96,20 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionMessage): void { $type = $this->getDayOfWeekType(); - $this->expectException($expectedExceptionClass); + $this->expectException(ConversionException::class); + $this->expectExceptionMessage($expectedExceptionMessage); $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array { return [ - [0, ValueError::class], - [8, ValueError::class], + [0, '0 is not a valid backing value for enum'], + [8, '8 is not a valid backing value for enum'], ]; } } diff --git a/tests/Types/DurationTypeTest.php b/tests/Types/DurationTypeTest.php index a73881f..aaa68c8 100644 --- a/tests/Types/DurationTypeTest.php +++ b/tests/Types/DurationTypeTest.php @@ -4,7 +4,6 @@ namespace Brick\DateTime\Doctrine\Tests\Types; -use Brick\DateTime\DateTimeException; use Brick\DateTime\Doctrine\Types\DurationType; use Brick\DateTime\LocalDate; use Brick\DateTime\Duration; @@ -85,20 +84,21 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionMessage): void { $type = $this->getDurationType(); - $this->expectException($expectedExceptionClass); + $this->expectException(ConversionException::class); + $this->expectExceptionMessage($expectedExceptionMessage); $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array { return [ - [0, DateTimeException::class], - ['10:31:00', DateTimeException::class], - ['2021-04-00', DateTimeException::class], + [0, 'Text cannot be parsed to a Duration: 0'], + ['10:31:00', 'Text cannot be parsed to a Duration: 10:31:00'], + ['2021-04-00', 'Text cannot be parsed to a Duration: 2021-04-00'], ]; } } diff --git a/tests/Types/LocalDateTimeTypeTest.php b/tests/Types/LocalDateTimeTypeTest.php index 65fd794..9121780 100644 --- a/tests/Types/LocalDateTimeTypeTest.php +++ b/tests/Types/LocalDateTimeTypeTest.php @@ -4,7 +4,6 @@ namespace Brick\DateTime\Doctrine\Tests\Types; -use Brick\DateTime\DateTimeException; use Brick\DateTime\Doctrine\Types\LocalDateTimeType; use Brick\DateTime\LocalDate; use Brick\DateTime\LocalDateTime; @@ -92,21 +91,22 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionMessage): void { $type = $this->getLocalDateTimeType(); - $this->expectException($expectedExceptionClass); + $this->expectException(ConversionException::class); + $this->expectExceptionMessage($expectedExceptionMessage); $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array { return [ - [0, DateTimeException::class], - ['01:02:59', DateTimeException::class], - ['2021-04-17', DateTimeException::class], - ['2021-04-17Z01:02:03.456', DateTimeException::class], + [0, 'Failed to parse "0"'], + ['01:02:59', 'Failed to parse "01:02:59".'], + ['2021-04-17', 'Failed to parse "2021-04-17".'], + ['2021-04-17Z01:02:03.456', 'Failed to parse "2021-04-17Z01:02:03.456".'], ]; } } diff --git a/tests/Types/LocalDateTypeTest.php b/tests/Types/LocalDateTypeTest.php index ad7b885..85f9f09 100644 --- a/tests/Types/LocalDateTypeTest.php +++ b/tests/Types/LocalDateTypeTest.php @@ -4,7 +4,6 @@ namespace Brick\DateTime\Doctrine\Tests\Types; -use Brick\DateTime\DateTimeException; use Brick\DateTime\Doctrine\Types\LocalDateType; use Brick\DateTime\LocalDate; use Brick\DateTime\LocalDateTime; @@ -85,20 +84,21 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionMessage): void { $type = $this->getLocalDateType(); - $this->expectException($expectedExceptionClass); + $this->expectException(ConversionException::class); + $this->expectExceptionMessage($expectedExceptionMessage); $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array { return [ - [0, DateTimeException::class], - ['10:31:00', DateTimeException::class], - ['2021-04-00', DateTimeException::class], + [0, 'Failed to parse "0".'], + ['10:31:00', 'Failed to parse "10:31:00".'], + ['2021-04-00', 'Invalid day-of-month: 0 is not in the range 1 to 31.'], ]; } } diff --git a/tests/Types/LocalTimeTypeTest.php b/tests/Types/LocalTimeTypeTest.php index 71e6df7..ec4454c 100644 --- a/tests/Types/LocalTimeTypeTest.php +++ b/tests/Types/LocalTimeTypeTest.php @@ -4,7 +4,6 @@ namespace Brick\DateTime\Doctrine\Tests\Types; -use Brick\DateTime\DateTimeException; use Brick\DateTime\Doctrine\Types\LocalTimeType; use Brick\DateTime\LocalDate; use Brick\DateTime\LocalTime; @@ -89,20 +88,21 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionMessage): void { $type = $this->getLocalTimeType(); - $this->expectException($expectedExceptionClass); + $this->expectException(ConversionException::class); + $this->expectExceptionMessage($expectedExceptionMessage); $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array { return [ - [0, DateTimeException::class], - ['01:02:60', DateTimeException::class], - ['2021-04-17', DateTimeException::class], + [0, 'Failed to parse "0".'], + ['01:02:60', 'Invalid second-of-minute: 60 is not in the range 0 to 59.'], + ['2021-04-17', 'Failed to parse "2021-04-17".'], ]; } } diff --git a/tests/Types/PeriodTypeTest.php b/tests/Types/PeriodTypeTest.php index 507d27c..ec5f643 100644 --- a/tests/Types/PeriodTypeTest.php +++ b/tests/Types/PeriodTypeTest.php @@ -4,7 +4,6 @@ namespace Brick\DateTime\Doctrine\Tests\Types; -use Brick\DateTime\DateTimeException; use Brick\DateTime\Doctrine\Types\PeriodType; use Brick\DateTime\LocalDate; use Brick\DateTime\Period; @@ -85,20 +84,21 @@ public static function providerConvertToPHPValue(): array } #[DataProvider('providerConvertToPHPValueWithInvalidValue')] - public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionClass): void + public function testConvertToPHPValueWithInvalidValue(mixed $value, string $expectedExceptionMessage): void { $type = $this->getPeriodType(); - $this->expectException($expectedExceptionClass); + $this->expectException(ConversionException::class); + $this->expectExceptionMessage($expectedExceptionMessage); $type->convertToPHPValue($value, new SQLitePlatform()); } public static function providerConvertToPHPValueWithInvalidValue(): array { return [ - [0, DateTimeException::class], - ['10:31:00', DateTimeException::class], - ['2021-04-00', DateTimeException::class], + [0, 'Text cannot be parsed to a Period: 0'], + ['10:31:00', 'Text cannot be parsed to a Period: 10:31:00'], + ['2021-04-00', 'Text cannot be parsed to a Period: 2021-04-00'], ]; } }