From ea53a6e97e017ac43f4b8506c41ffb21d898ff63 Mon Sep 17 00:00:00 2001 From: Robin Gustafsson Date: Wed, 14 Jun 2023 22:21:17 +0200 Subject: [PATCH] Fix PHPUnit 10 compatibility --- composer.json | 2 +- src/Carbon/Doctrine/CarbonTypeConverter.php | 6 ++--- src/Carbon/Doctrine/DateTimeImmutableType.php | 17 ++++++++++++- tests/Carbon/ObjectsTest.php | 24 +++++++++---------- tests/CarbonImmutable/ObjectsTest.php | 24 +++++++++---------- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index 7560763027..4f1e75ff56 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12.99 || ^1.7.14", "phpunit/php-file-iterator": "^2.0.5 || ^3.0.6", - "phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20", + "phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20 || ^10.2.6", "squizlabs/php_codesniffer": "^3.4" }, "provide": { diff --git a/src/Carbon/Doctrine/CarbonTypeConverter.php b/src/Carbon/Doctrine/CarbonTypeConverter.php index ecfe17e793..8ff33aea4c 100644 --- a/src/Carbon/Doctrine/CarbonTypeConverter.php +++ b/src/Carbon/Doctrine/CarbonTypeConverter.php @@ -34,7 +34,7 @@ protected function getCarbonClassName(): string /** * @return string */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { $precision = $fieldDeclaration['precision'] ?: 10; @@ -66,7 +66,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla * * @return T|null */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface { $class = $this->getCarbonClassName(); @@ -104,7 +104,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) * * @return string|null */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; diff --git a/src/Carbon/Doctrine/DateTimeImmutableType.php b/src/Carbon/Doctrine/DateTimeImmutableType.php index 499271031e..22169dc99c 100644 --- a/src/Carbon/Doctrine/DateTimeImmutableType.php +++ b/src/Carbon/Doctrine/DateTimeImmutableType.php @@ -7,12 +7,17 @@ namespace Carbon\Doctrine; use Carbon\CarbonImmutable; +use DateTimeImmutable; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\VarDateTimeImmutableType; class DateTimeImmutableType extends VarDateTimeImmutableType implements CarbonDoctrineType { /** @use CarbonTypeConverter */ - use CarbonTypeConverter; + use CarbonTypeConverter + { + convertToPHPValue as private baseConvertToPHPValue; + } /** * @return class-string @@ -21,4 +26,14 @@ protected function getCarbonClassName(): string { return CarbonImmutable::class; } + + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @return T|null + */ + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeImmutable + { + return $this->baseConvertToPHPValue($value, $platform); + } } diff --git a/tests/Carbon/ObjectsTest.php b/tests/Carbon/ObjectsTest.php index e5a4d5f768..2a837aad99 100644 --- a/tests/Carbon/ObjectsTest.php +++ b/tests/Carbon/ObjectsTest.php @@ -28,40 +28,40 @@ public function testToObject() $this->assertInstanceOf(stdClass::class, $dtToObject); - $this->assertObjectHasAttribute('year', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'year')); $this->assertSame($dt->year, $dtToObject->year); - $this->assertObjectHasAttribute('month', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'month')); $this->assertSame($dt->month, $dtToObject->month); - $this->assertObjectHasAttribute('day', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'day')); $this->assertSame($dt->day, $dtToObject->day); - $this->assertObjectHasAttribute('dayOfWeek', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'dayOfWeek')); $this->assertSame($dt->dayOfWeek, $dtToObject->dayOfWeek); - $this->assertObjectHasAttribute('dayOfYear', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'dayOfYear')); $this->assertSame($dt->dayOfYear, $dtToObject->dayOfYear); - $this->assertObjectHasAttribute('hour', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'hour')); $this->assertSame($dt->hour, $dtToObject->hour); - $this->assertObjectHasAttribute('minute', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'minute')); $this->assertSame($dt->minute, $dtToObject->minute); - $this->assertObjectHasAttribute('second', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'second')); $this->assertSame($dt->second, $dtToObject->second); - $this->assertObjectHasAttribute('micro', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'micro')); $this->assertSame($dt->micro, $dtToObject->micro); - $this->assertObjectHasAttribute('timestamp', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'timestamp')); $this->assertSame($dt->timestamp, $dtToObject->timestamp); - $this->assertObjectHasAttribute('timezone', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'timezone')); $this->assertEquals($dt->timezone, $dtToObject->timezone); - $this->assertObjectHasAttribute('formatted', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'formatted')); $this->assertSame($dt->format(Carbon::DEFAULT_TO_STRING_FORMAT), $dtToObject->formatted); } diff --git a/tests/CarbonImmutable/ObjectsTest.php b/tests/CarbonImmutable/ObjectsTest.php index 3ae51523bb..ffb9ccf80d 100644 --- a/tests/CarbonImmutable/ObjectsTest.php +++ b/tests/CarbonImmutable/ObjectsTest.php @@ -28,40 +28,40 @@ public function testToObject() $this->assertInstanceOf(stdClass::class, $dtToObject); - $this->assertObjectHasAttribute('year', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'year')); $this->assertSame($dt->year, $dtToObject->year); - $this->assertObjectHasAttribute('month', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'month')); $this->assertSame($dt->month, $dtToObject->month); - $this->assertObjectHasAttribute('day', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'day')); $this->assertSame($dt->day, $dtToObject->day); - $this->assertObjectHasAttribute('dayOfWeek', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'dayOfWeek')); $this->assertSame($dt->dayOfWeek, $dtToObject->dayOfWeek); - $this->assertObjectHasAttribute('dayOfYear', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'dayOfYear')); $this->assertSame($dt->dayOfYear, $dtToObject->dayOfYear); - $this->assertObjectHasAttribute('hour', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'hour')); $this->assertSame($dt->hour, $dtToObject->hour); - $this->assertObjectHasAttribute('minute', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'minute')); $this->assertSame($dt->minute, $dtToObject->minute); - $this->assertObjectHasAttribute('second', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'second')); $this->assertSame($dt->second, $dtToObject->second); - $this->assertObjectHasAttribute('micro', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'micro')); $this->assertSame($dt->micro, $dtToObject->micro); - $this->assertObjectHasAttribute('timestamp', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'timestamp')); $this->assertSame($dt->timestamp, $dtToObject->timestamp); - $this->assertObjectHasAttribute('timezone', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'timezone')); $this->assertEquals($dt->timezone, $dtToObject->timezone); - $this->assertObjectHasAttribute('formatted', $dtToObject); + $this->assertTrue(property_exists($dtToObject, 'formatted')); $this->assertSame($dt->format(Carbon::DEFAULT_TO_STRING_FORMAT), $dtToObject->formatted); }