[DoctrineBridge] accept converting Uid-as-strings to db-values
This commit is contained in:
parent
57e39b41b9
commit
20714d66c9
@ -52,11 +52,12 @@ class UlidBinaryTypeTest extends TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedStringUlidConversionToDatabaseValue()
|
||||
public function testStringUlidConvertsToDatabaseValue()
|
||||
{
|
||||
$this->expectException(ConversionException::class);
|
||||
$expected = Ulid::fromString(self::DUMMY_ULID)->toBinary();
|
||||
$actual = $this->type->convertToDatabaseValue(self::DUMMY_ULID, $this->platform);
|
||||
|
||||
$this->type->convertToDatabaseValue(self::DUMMY_ULID, $this->platform);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedTypeConversionForDatabaseValue()
|
||||
|
@ -68,11 +68,14 @@ final class UlidTypeTest extends TestCase
|
||||
$this->assertEquals('foo', $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedUlidStringConversionToDatabaseValue()
|
||||
public function testUlidStringConvertsToDatabaseValue()
|
||||
{
|
||||
$this->expectException(ConversionException::class);
|
||||
$actual = $this->type->convertToDatabaseValue(self::DUMMY_ULID, $this->platform);
|
||||
$ulid = Ulid::fromString(self::DUMMY_ULID);
|
||||
|
||||
$this->type->convertToDatabaseValue(self::DUMMY_ULID, $this->platform);
|
||||
$expected = $ulid->toRfc4122();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedTypeConversionForDatabaseValue()
|
||||
|
@ -52,11 +52,21 @@ class UuidBinaryTypeTest extends TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedStringUuidConversionToDatabaseValue()
|
||||
public function testStringUuidConvertsToDatabaseValue()
|
||||
{
|
||||
$uuid = self::DUMMY_UUID;
|
||||
|
||||
$expected = uuid_parse(self::DUMMY_UUID);
|
||||
$actual = $this->type->convertToDatabaseValue($uuid, $this->platform);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testInvalidUuidConversionForDatabaseValue()
|
||||
{
|
||||
$this->expectException(ConversionException::class);
|
||||
|
||||
$this->type->convertToDatabaseValue(self::DUMMY_UUID, $this->platform);
|
||||
$this->type->convertToDatabaseValue('abcdefg', $this->platform);
|
||||
}
|
||||
|
||||
public function testNullConversionForDatabaseValue()
|
||||
|
@ -68,11 +68,11 @@ final class UuidTypeTest extends TestCase
|
||||
$this->assertEquals('foo', $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedUuidStringConversionToDatabaseValue()
|
||||
public function testUuidStringConvertsToDatabaseValue()
|
||||
{
|
||||
$this->expectException(ConversionException::class);
|
||||
$actual = $this->type->convertToDatabaseValue(self::DUMMY_UUID, $this->platform);
|
||||
|
||||
$this->type->convertToDatabaseValue(self::DUMMY_UUID, $this->platform);
|
||||
$this->assertEquals(self::DUMMY_UUID, $actual);
|
||||
}
|
||||
|
||||
public function testNotSupportedTypeConversionForDatabaseValue()
|
||||
|
@ -61,11 +61,19 @@ abstract class AbstractBinaryUidType extends Type
|
||||
return $value->toBinary();
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', AbstractUid::class]);
|
||||
if (!\is_string($value)) {
|
||||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'string', AbstractUid::class]);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->getUidClass()::fromString($value)->toBinary();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw ConversionException::conversionFailed($value, $this->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,11 +61,19 @@ abstract class AbstractUidType extends Type
|
||||
return $value->toRfc4122();
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', AbstractUid::class]);
|
||||
if (!\is_string($value)) {
|
||||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'string', AbstractUid::class]);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->getUidClass()::fromString($value)->toRfc4122();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw ConversionException::conversionFailed($value, $this->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user