Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Infrastructure/Doctrine/Type/AbstractIdType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
return $value;
}

if ($value === null) {
return null;
}

if (!$value instanceof Id) {
throw ConversionException::conversionFailedInvalidType(
$value,
Expand All @@ -30,6 +34,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}

$idType = $this->getIdType();
if (!is_subclass_of($idType, Id::class)) {
throw ConversionException::conversionFailedUnserialization(
Expand Down
8 changes: 8 additions & 0 deletions src/Infrastructure/Doctrine/Type/AbstractUuidType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
return $value;
}

if ($value === null) {
return null;
}

if (!$value instanceof Uuid) {
throw ConversionException::conversionFailedInvalidType(
$value,
Expand All @@ -38,6 +42,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}

$idType = $this->getIdType();
if (!is_subclass_of($idType, Uuid::class)) {
throw ConversionException::conversionFailedUnserialization(
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Infrastructure/Doctrine/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mockery;
use PHPUnit\Framework\TestCase;

class DoctrinePaginatorTest extends TestCase
class PaginatorTest extends TestCase
{
/** @var OrmPaginator|Mockery\MockInterface */
private mixed $ormPaginatorMock;
Expand Down
26 changes: 26 additions & 0 deletions tests/Unit/Infrastructure/Doctrine/Type/AbstractIdTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ public function testConvertToDatabaseValueInvalidType(): void
$type->convertToDatabaseValue('foo', $platform);
}

public function testConvertToDatabaseValueNull(): void
{
// Given
$type = new FooIdType();
$platform = Mockery::mock(AbstractPlatform::class);

// When
$result = $type->convertToDatabaseValue(null, $platform);

// Then
$this->assertNull($result);
}

public function testConvertToPhpValue(): void
{
// Given
Expand All @@ -91,4 +104,17 @@ public function testConvertToPhpValue(): void
$this->assertInstanceOf(FooId::class, $result);
$this->assertSame($intId, $result->getValue());
}

public function testConvertToPhpValueNull(): void
{
// Given
$type = new FooIdType();
$platform = Mockery::mock(AbstractPlatform::class);

// When
$result = $type->convertToPHPValue(null, $platform);

// Then
$this->assertNull($result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ public function testConvertToDatabaseValueScalar(): void
$this->assertSame($uuidString, $result);
}

public function testConvertToDatabaseValueNull(): void
{
// Given
$platform = Mockery::mock(AbstractPlatform::class);
$type = new FooUuidType();

// When
$result = $type->convertToDatabaseValue(null, $platform);

// Then
$this->assertNull($result);
}

public function testConvertToDatabaseValueInvalidType(): void
{
// Given
Expand Down Expand Up @@ -90,4 +103,17 @@ public function testConvertToPhpValue(): void
$this->assertInstanceOf(FooUuid::class, $result);
$this->assertSame($uuidString, $result->getValue());
}

public function testConvertToPhpValueNull(): void
{
// Given
$platform = Mockery::mock(AbstractPlatform::class);
$type = new FooUuidType();

// When
$result = $type->convertToPHPValue(null, $platform);

// Then
$this->assertNull($result);
}
}