Skip to content

Commit

Permalink
Fix PHPUnit 10 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rgson committed Aug 4, 2023
1 parent 4308217 commit ea53a6e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/Carbon/Doctrine/CarbonTypeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion src/Carbon/Doctrine/DateTimeImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<CarbonImmutable> */
use CarbonTypeConverter;
use CarbonTypeConverter
{
convertToPHPValue as private baseConvertToPHPValue;
}

/**
* @return class-string<CarbonImmutable>
Expand All @@ -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

Check failure on line 35 in src/Carbon/Doctrine/DateTimeImmutableType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1)

Method Carbon\Doctrine\DateTimeImmutableType::convertToPHPValue() has invalid return type Carbon\Doctrine\T.

Check failure on line 35 in src/Carbon/Doctrine/DateTimeImmutableType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1)

PHPDoc tag @return with type Carbon\Doctrine\T|null is not subtype of native type DateTimeImmutable|null.
{
return $this->baseConvertToPHPValue($value, $platform);
}
}
24 changes: 12 additions & 12 deletions tests/Carbon/ObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 12 additions & 12 deletions tests/CarbonImmutable/ObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ea53a6e

Please sign in to comment.