Skip to content

Commit cf26413

Browse files
committed
fix(types): fix on object usage
1 parent 8f81911 commit cf26413

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/Ulid/UlidType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\DBAL\Types\ConversionException;
99
use Doctrine\DBAL\Types\GuidType;
1010
use Symfony\Component\Uid\Ulid;
11-
use Throwable;
1211

1312
/**
1413
* @author Guillaume Loulier <[email protected]>
@@ -42,6 +41,10 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
4241
return null;
4342
}
4443

44+
if ($value instanceof Ulid) {
45+
return $value;
46+
}
47+
4548
if (!Ulid::isValid($value)) {
4649
throw ConversionException::conversionFailed($value, self::NAME);
4750
}

src/Uuid/UuidType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
4242
return null;
4343
}
4444

45+
if ($value instanceof Uuid) {
46+
return $value;
47+
}
48+
4549
if (!Uuid::isValid($value)) {
4650
throw ConversionException::conversionFailed($value, self::NAME);
4751
}

tests/Ulid/UlidTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,14 @@ public function testTypeCanBeConvertedToPHPValueWhenUsingValidString(): void
102102
$value = Type::getType('ulid')->convertToPHPValue(strtr($entryValue, ['-' => '0']), $platform);
103103
static::assertInstanceOf(Ulid::class, $value);
104104
}
105+
106+
public function testTypeCanBeConvertedToPHPValueWhenUsingAnUlidObject(): void
107+
{
108+
$platform = $this->createMock(AbstractPlatform::class);
109+
110+
$ulid = new Ulid();
111+
112+
$value = Type::getType('ulid')->convertToPHPValue($ulid, $platform);
113+
static::assertInstanceOf(Ulid::class, $value);
114+
}
105115
}

tests/Uuid/UuidTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,14 @@ public function testTypeCanBeConvertedToPHPValueWhenUsingUuid(): void
9797
$value = Type::getType('uuid')->convertToPHPValue($uuid->toRfc4122(), $platform);
9898
static::assertInstanceOf(Uuid::class, $value);
9999
}
100+
101+
public function testTypeCanBeConvertedToPHPValueWhenUsingAnUuidObject(): void
102+
{
103+
$platform = $this->createMock(AbstractPlatform::class);
104+
105+
$uuid = Uuid::v4();
106+
107+
$value = Type::getType('uuid')->convertToPHPValue($uuid, $platform);
108+
static::assertInstanceOf(Uuid::class, $value);
109+
}
100110
}

0 commit comments

Comments
 (0)