diff --git a/docs/en/reference/types.rst b/docs/en/reference/types.rst index 1cad37e9465..b8b3ea56a36 100644 --- a/docs/en/reference/types.rst +++ b/docs/en/reference/types.rst @@ -845,8 +845,6 @@ Now we implement our ``Doctrine\DBAL\Types\Type`` instance: */ class MoneyType extends Type { - const MONEY = 'money'; // modify to match your type name - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return 'MyMoney'; @@ -861,11 +859,6 @@ Now we implement our ``Doctrine\DBAL\Types\Type`` instance: { return $value->toDecimal(); } - - public function getName() - { - return self::MONEY; - } } The job of Doctrine-DBAL is to transform your type into an SQL diff --git a/src/Types/ArrayType.php b/src/Types/ArrayType.php index 3137e03f37a..1be1c2000bb 100644 --- a/src/Types/ArrayType.php +++ b/src/Types/ArrayType.php @@ -55,14 +55,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::ARRAY; - } - /** * {@inheritdoc} */ diff --git a/src/Types/AsciiStringType.php b/src/Types/AsciiStringType.php index ab1e0e06145..b7c39ffa3ba 100644 --- a/src/Types/AsciiStringType.php +++ b/src/Types/AsciiStringType.php @@ -21,9 +21,4 @@ public function getBindingType(): int { return ParameterType::ASCII; } - - public function getName(): string - { - return Types::ASCII_STRING; - } } diff --git a/src/Types/BigIntType.php b/src/Types/BigIntType.php index e5d6dcbbf65..8006e2d40e4 100644 --- a/src/Types/BigIntType.php +++ b/src/Types/BigIntType.php @@ -10,14 +10,6 @@ */ class BigIntType extends Type implements PhpIntegerMappingType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::BIGINT; - } - /** * {@inheritdoc} */ diff --git a/src/Types/BinaryType.php b/src/Types/BinaryType.php index e030f166029..a2202fad519 100644 --- a/src/Types/BinaryType.php +++ b/src/Types/BinaryType.php @@ -49,14 +49,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return $value; } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::BINARY; - } - /** * {@inheritdoc} */ diff --git a/src/Types/BlobType.php b/src/Types/BlobType.php index b71e7255eb8..2612ee45827 100644 --- a/src/Types/BlobType.php +++ b/src/Types/BlobType.php @@ -49,14 +49,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return $value; } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::BLOB; - } - /** * {@inheritdoc} */ diff --git a/src/Types/BooleanType.php b/src/Types/BooleanType.php index f6e4df3b2c6..0058b2e9404 100644 --- a/src/Types/BooleanType.php +++ b/src/Types/BooleanType.php @@ -34,14 +34,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return $platform->convertFromBoolean($value); } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::BOOLEAN; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateImmutableType.php b/src/Types/DateImmutableType.php index 4fbe6a472a1..97b9bcbec7e 100644 --- a/src/Types/DateImmutableType.php +++ b/src/Types/DateImmutableType.php @@ -10,14 +10,6 @@ */ class DateImmutableType extends DateType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATE_IMMUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateIntervalType.php b/src/Types/DateIntervalType.php index 6ecd4989c4d..a32b7d891a7 100644 --- a/src/Types/DateIntervalType.php +++ b/src/Types/DateIntervalType.php @@ -15,14 +15,6 @@ class DateIntervalType extends Type { public const FORMAT = '%RP%YY%MM%DDT%HH%IM%SS'; - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATEINTERVAL; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateTimeImmutableType.php b/src/Types/DateTimeImmutableType.php index fd77519773e..09107a0f4ed 100644 --- a/src/Types/DateTimeImmutableType.php +++ b/src/Types/DateTimeImmutableType.php @@ -12,14 +12,6 @@ */ class DateTimeImmutableType extends DateTimeType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATETIME_IMMUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateTimeType.php b/src/Types/DateTimeType.php index 454295d710f..fd7c98e2c34 100644 --- a/src/Types/DateTimeType.php +++ b/src/Types/DateTimeType.php @@ -13,14 +13,6 @@ */ class DateTimeType extends Type implements PhpDateTimeMappingType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATETIME_MUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateTimeTzImmutableType.php b/src/Types/DateTimeTzImmutableType.php index 6e707e065dc..d9ace684ece 100644 --- a/src/Types/DateTimeTzImmutableType.php +++ b/src/Types/DateTimeTzImmutableType.php @@ -10,14 +10,6 @@ */ class DateTimeTzImmutableType extends DateTimeTzType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATETIMETZ_IMMUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateTimeTzType.php b/src/Types/DateTimeTzType.php index 29672397f05..05f5f18e90b 100644 --- a/src/Types/DateTimeTzType.php +++ b/src/Types/DateTimeTzType.php @@ -24,14 +24,6 @@ */ class DateTimeTzType extends Type implements PhpDateTimeMappingType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATETIMETZ_MUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DateType.php b/src/Types/DateType.php index 6f86f5436f8..a2819e9b3bf 100644 --- a/src/Types/DateType.php +++ b/src/Types/DateType.php @@ -11,14 +11,6 @@ */ class DateType extends Type { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATE_MUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/DecimalType.php b/src/Types/DecimalType.php index c70067f2b4f..b339619a6be 100644 --- a/src/Types/DecimalType.php +++ b/src/Types/DecimalType.php @@ -14,14 +14,6 @@ */ class DecimalType extends Type { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DECIMAL; - } - /** * {@inheritdoc} */ diff --git a/src/Types/FloatType.php b/src/Types/FloatType.php index 98ead4a9d6a..d924ae2ad9d 100644 --- a/src/Types/FloatType.php +++ b/src/Types/FloatType.php @@ -6,14 +6,6 @@ class FloatType extends Type { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::FLOAT; - } - /** * {@inheritdoc} */ diff --git a/src/Types/GuidType.php b/src/Types/GuidType.php index a4974f9d05e..d4e4869eb79 100644 --- a/src/Types/GuidType.php +++ b/src/Types/GuidType.php @@ -17,14 +17,6 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform) return $platform->getGuidTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::GUID; - } - /** * {@inheritdoc} */ diff --git a/src/Types/IntegerType.php b/src/Types/IntegerType.php index 0df606e2982..21f34b8ef21 100644 --- a/src/Types/IntegerType.php +++ b/src/Types/IntegerType.php @@ -10,14 +10,6 @@ */ class IntegerType extends Type implements PhpIntegerMappingType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::INTEGER; - } - /** * {@inheritdoc} */ diff --git a/src/Types/JsonType.php b/src/Types/JsonType.php index 55a017b8c8c..c62073ddd78 100644 --- a/src/Types/JsonType.php +++ b/src/Types/JsonType.php @@ -61,14 +61,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::JSON; - } - /** * {@inheritdoc} */ diff --git a/src/Types/ObjectType.php b/src/Types/ObjectType.php index 49042c1bf6d..1fe033a844a 100644 --- a/src/Types/ObjectType.php +++ b/src/Types/ObjectType.php @@ -54,14 +54,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::OBJECT; - } - /** * {@inheritdoc} */ diff --git a/src/Types/SimpleArrayType.php b/src/Types/SimpleArrayType.php index ee9c7f2dfa0..d90bb9e30b6 100644 --- a/src/Types/SimpleArrayType.php +++ b/src/Types/SimpleArrayType.php @@ -52,14 +52,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return explode(',', $value); } - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::SIMPLE_ARRAY; - } - /** * {@inheritdoc} */ diff --git a/src/Types/SmallIntType.php b/src/Types/SmallIntType.php index 90e63495137..924341d1537 100644 --- a/src/Types/SmallIntType.php +++ b/src/Types/SmallIntType.php @@ -10,14 +10,6 @@ */ class SmallIntType extends Type implements PhpIntegerMappingType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::SMALLINT; - } - /** * {@inheritdoc} */ diff --git a/src/Types/StringType.php b/src/Types/StringType.php index 4e7bd55d07c..bc8889012e0 100644 --- a/src/Types/StringType.php +++ b/src/Types/StringType.php @@ -16,12 +16,4 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform) { return $platform->getVarcharTypeDeclarationSQL($column); } - - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::STRING; - } } diff --git a/src/Types/TextType.php b/src/Types/TextType.php index b1e640b6952..60ed5015417 100644 --- a/src/Types/TextType.php +++ b/src/Types/TextType.php @@ -27,12 +27,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform) { return is_resource($value) ? stream_get_contents($value) : $value; } - - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::TEXT; - } } diff --git a/src/Types/TimeImmutableType.php b/src/Types/TimeImmutableType.php index 8d2c1517ccb..4f80a25adf0 100644 --- a/src/Types/TimeImmutableType.php +++ b/src/Types/TimeImmutableType.php @@ -10,14 +10,6 @@ */ class TimeImmutableType extends TimeType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::TIME_IMMUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/TimeType.php b/src/Types/TimeType.php index 4f2c8c6310d..edb477df73a 100644 --- a/src/Types/TimeType.php +++ b/src/Types/TimeType.php @@ -11,14 +11,6 @@ */ class TimeType extends Type { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::TIME_MUTABLE; - } - /** * {@inheritdoc} */ diff --git a/src/Types/Type.php b/src/Types/Type.php index 03e5b824851..ba761e5774b 100644 --- a/src/Types/Type.php +++ b/src/Types/Type.php @@ -103,10 +103,11 @@ abstract public function getSQLDeclaration(array $column, AbstractPlatform $plat * Gets the name of this type. * * @return string - * - * @todo Needed? */ - abstract public function getName(); + public function getName() + { + return self::getTypeRegistry()->lookupName($this); + } final public static function getTypeRegistry(): TypeRegistry { diff --git a/src/Types/VarDateTimeImmutableType.php b/src/Types/VarDateTimeImmutableType.php index f4f5e3ec38f..820fcc27c24 100644 --- a/src/Types/VarDateTimeImmutableType.php +++ b/src/Types/VarDateTimeImmutableType.php @@ -12,14 +12,6 @@ */ class VarDateTimeImmutableType extends VarDateTimeType { - /** - * {@inheritdoc} - */ - public function getName() - { - return Types::DATETIME_IMMUTABLE; - } - /** * {@inheritdoc} */ diff --git a/tests/Functional/Schema/MySQL/PointType.php b/tests/Functional/Schema/MySQL/PointType.php index e05331c10c7..6f25326b031 100644 --- a/tests/Functional/Schema/MySQL/PointType.php +++ b/tests/Functional/Schema/MySQL/PointType.php @@ -9,14 +9,6 @@ class PointType extends Type { - /** - * {@inheritDoc} - */ - public function getName() - { - return 'point'; - } - /** * {@inheritDoc} */ diff --git a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php index a7bcf31f139..9bce6a94c36 100644 --- a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php @@ -543,14 +543,6 @@ public static function autoIncrementTypeMigrations(): iterable class MoneyType extends Type { - /** - * {@inheritDoc} - */ - public function getName() - { - return 'MyMoney'; - } - /** * {@inheritDoc} */ diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 4eab450309e..60019b53ed5 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -123,35 +123,20 @@ public function testRegistersCommentedDoctrineMappingTypeImplicitly(): void self::assertTrue($this->platform->isCommentedDoctrineType($type)); } - /** - * @dataProvider getIsCommentedDoctrineType - */ - public function testIsCommentedDoctrineType(Type $type, bool $commented): void - { - self::assertSame($commented, $this->platform->isCommentedDoctrineType($type)); - } - - /** - * @return mixed[] - */ - public function getIsCommentedDoctrineType(): iterable + public function testIsCommentedDoctrineType(): void { - $this->setUp(); - - $data = []; - foreach (Type::getTypesMap() as $typeName => $className) { $type = Type::getType($typeName); - $data[$typeName] = [ - $type, + self::assertSame( $type->requiresSQLCommentHint($this->platform), - ]; + $this->platform->isCommentedDoctrineType($type), + $typeName + ); } - - return $data; } + public function testCreateWithNoColumns(): void { $table = new Table('test'); diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index a2462d75a9a..9d631879d82 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -289,16 +289,21 @@ public function testGeneratesColumnTypesDeclarationSQL(): void self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef)); } - /** - * {@inheritDoc} - */ - public function getIsCommentedDoctrineType(): array + public function testIsCommentedDoctrineType(): void { - $data = parent::getIsCommentedDoctrineType(); + foreach (Type::getTypesMap() as $typeName => $className) { + $type = Type::getType($typeName); - $data[Types::BOOLEAN] = [Type::getType(Types::BOOLEAN), true]; + if ($typeName === Types::BOOLEAN) { + self::assertTrue($this->platform->isCommentedDoctrineType($type)); + continue; + } - return $data; + self::assertSame( + $type->requiresSQLCommentHint($this->platform), + $this->platform->isCommentedDoctrineType($type) + ); + } } public function testGeneratesDDLSnippets(): void diff --git a/tests/Types/ArrayTest.php b/tests/Types/ArrayTest.php index f7f823cfcac..d761311d3ab 100644 --- a/tests/Types/ArrayTest.php +++ b/tests/Types/ArrayTest.php @@ -5,9 +5,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ArrayType; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function serialize; class ArrayTest extends TestCase @@ -21,7 +24,9 @@ class ArrayTest extends TestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new ArrayType(); + $type = Type::getType(Types::ARRAY); + assert($type instanceof ArrayType); + $this->type = $type; } public function testArrayConvertsToDatabaseValue(): void diff --git a/tests/Types/BinaryTest.php b/tests/Types/BinaryTest.php index 47c363b563e..047ed16f323 100644 --- a/tests/Types/BinaryTest.php +++ b/tests/Types/BinaryTest.php @@ -6,10 +6,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function base64_encode; use function fopen; use function stream_get_contents; @@ -25,7 +27,9 @@ class BinaryTest extends TestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new BinaryType(); + $type = Type::getType(Types::BINARY); + assert($type instanceof BinaryType); + $this->type = $type; } public function testReturnsBindingType(): void diff --git a/tests/Types/DateImmutableTypeTest.php b/tests/Types/DateImmutableTypeTest.php index e31852c1f03..45ce777d919 100644 --- a/tests/Types/DateImmutableTypeTest.php +++ b/tests/Types/DateImmutableTypeTest.php @@ -8,9 +8,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function get_class; class DateImmutableTypeTest extends TestCase @@ -24,7 +27,9 @@ class DateImmutableTypeTest extends TestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new DateImmutableType(); + $type = Type::getType(Types::DATE_IMMUTABLE); + assert($type instanceof DateImmutableType); + $this->type = $type; } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Types/DateIntervalTest.php b/tests/Types/DateIntervalTest.php index 8e1a8fc33fb..aa32c8a68ee 100644 --- a/tests/Types/DateIntervalTest.php +++ b/tests/Types/DateIntervalTest.php @@ -7,10 +7,14 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateIntervalType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; +use function assert; + final class DateIntervalTest extends TestCase { /** @var AbstractPlatform&MockObject */ @@ -22,7 +26,9 @@ final class DateIntervalTest extends TestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new DateIntervalType(); + $type = Type::getType(Types::DATEINTERVAL); + assert($type instanceof DateIntervalType); + $this->type = $type; } public function testDateIntervalConvertsToDatabaseValue(): void diff --git a/tests/Types/DateTest.php b/tests/Types/DateTest.php index 7e84743671d..2215c85758f 100644 --- a/tests/Types/DateTest.php +++ b/tests/Types/DateTest.php @@ -4,7 +4,8 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\DateType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use function date_default_timezone_set; @@ -12,7 +13,7 @@ class DateTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = new DateType(); + $this->type = Type::getType(Types::DATE_MUTABLE); parent::setUp(); } diff --git a/tests/Types/DateTimeImmutableTypeTest.php b/tests/Types/DateTimeImmutableTypeTest.php index 9ba05db06b1..eea66c0ad2b 100644 --- a/tests/Types/DateTimeImmutableTypeTest.php +++ b/tests/Types/DateTimeImmutableTypeTest.php @@ -8,9 +8,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function get_class; class DateTimeImmutableTypeTest extends TestCase @@ -24,7 +27,9 @@ class DateTimeImmutableTypeTest extends TestCase protected function setUp(): void { $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); - $this->type = new DateTimeImmutableType(); + $type = Type::getType(Types::DATETIME_IMMUTABLE); + assert($type instanceof DateTimeImmutableType); + $this->type = $type; } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Types/DateTimeTest.php b/tests/Types/DateTimeTest.php index 3198daa947c..550568a3a2d 100644 --- a/tests/Types/DateTimeTest.php +++ b/tests/Types/DateTimeTest.php @@ -4,13 +4,14 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\DateTimeType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class DateTimeTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = new DateTimeType(); + $this->type = Type::getType(Types::DATETIME_MUTABLE); parent::setUp(); } diff --git a/tests/Types/DateTimeTzImmutableTypeTest.php b/tests/Types/DateTimeTzImmutableTypeTest.php index 358ba078e08..d58566b6ea1 100644 --- a/tests/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Types/DateTimeTzImmutableTypeTest.php @@ -8,9 +8,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function get_class; class DateTimeTzImmutableTypeTest extends TestCase @@ -24,7 +27,9 @@ class DateTimeTzImmutableTypeTest extends TestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new DateTimeTzImmutableType(); + $type = Type::getType(Types::DATETIMETZ_IMMUTABLE); + assert($type instanceof DateTimeTzImmutableType); + $this->type = $type; } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Types/DateTimeTzTest.php b/tests/Types/DateTimeTzTest.php index 04c386edc5d..76662564cd8 100644 --- a/tests/Types/DateTimeTzTest.php +++ b/tests/Types/DateTimeTzTest.php @@ -4,13 +4,14 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\DateTimeTzType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class DateTimeTzTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = new DateTimeTzType(); + $this->type = Type::getType(Types::DATETIMETZ_MUTABLE); parent::setUp(); } diff --git a/tests/Types/JsonTest.php b/tests/Types/JsonTest.php index 608fd656a59..7690d384a2d 100644 --- a/tests/Types/JsonTest.php +++ b/tests/Types/JsonTest.php @@ -6,10 +6,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\JsonType; +use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function base64_encode; use function fopen; use function json_encode; @@ -27,7 +29,9 @@ class JsonTest extends TestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new JsonType(); + $type = Type::getType(Types::JSON); + assert($type instanceof JsonType); + $this->type = $type; } public function testReturnsBindingType(): void diff --git a/tests/Types/ObjectTest.php b/tests/Types/ObjectTest.php index be4133d4df2..d482e5da2da 100644 --- a/tests/Types/ObjectTest.php +++ b/tests/Types/ObjectTest.php @@ -5,10 +5,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ObjectType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; +use function assert; use function serialize; class ObjectTest extends TestCase @@ -23,6 +26,9 @@ protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); $this->type = new ObjectType(); + $type = Type::getType(Types::OBJECT); + assert($type instanceof ObjectType); + $this->type = $type; } public function testObjectConvertsToDatabaseValue(): void diff --git a/tests/Types/TimeImmutableTypeTest.php b/tests/Types/TimeImmutableTypeTest.php index 223d4d677ad..e8bccf80b0e 100644 --- a/tests/Types/TimeImmutableTypeTest.php +++ b/tests/Types/TimeImmutableTypeTest.php @@ -8,9 +8,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function assert; use function get_class; class TimeImmutableTypeTest extends TestCase @@ -24,7 +27,9 @@ class TimeImmutableTypeTest extends TestCase protected function setUp(): void { $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); - $this->type = new TimeImmutableType(); + $type = Type::getType(Types::TIME_IMMUTABLE); + assert($type instanceof TimeImmutableType); + $this->type = $type; } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Types/TimeTest.php b/tests/Types/TimeTest.php index 2fe2e5a8a34..658ff946d58 100644 --- a/tests/Types/TimeTest.php +++ b/tests/Types/TimeTest.php @@ -4,13 +4,14 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\TimeType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class TimeTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = new TimeType(); + $this->type = Type::getType(Types::TIME_MUTABLE); parent::setUp(); } diff --git a/tests/Types/VarDateTimeImmutableTypeTest.php b/tests/Types/VarDateTimeImmutableTypeTest.php index f984fe8cce8..340e8aa6059 100644 --- a/tests/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Types/VarDateTimeImmutableTypeTest.php @@ -7,6 +7,8 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\VarDateTimeImmutableType; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -19,10 +21,23 @@ class VarDateTimeImmutableTypeTest extends TestCase /** @var VarDateTimeImmutableType */ private $type; + /** @var Type */ + private $backedUpType; + protected function setUp(): void { - $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); - $this->type = new VarDateTimeImmutableType(); + $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->type = new VarDateTimeImmutableType(); + $this->backedUpType = Type::getType(Types::DATETIME_IMMUTABLE); + Type::getTypeRegistry()->override(Types::DATETIME_IMMUTABLE, $this->type); + } + + public function tearDown(): void + { + Type::getTypeRegistry()->override( + Types::DATETIME_IMMUTABLE, + $this->backedUpType + ); } public function testReturnsName(): void diff --git a/tests/Types/VarDateTimeTest.php b/tests/Types/VarDateTimeTest.php index 3c447d77a49..cdc902ead00 100644 --- a/tests/Types/VarDateTimeTest.php +++ b/tests/Types/VarDateTimeTest.php @@ -5,6 +5,8 @@ use DateTime; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\VarDateTimeType; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -17,10 +19,23 @@ class VarDateTimeTest extends TestCase /** @var VarDateTimeType */ private $type; + /** @var Type */ + private $backedUpType; + protected function setUp(): void { - $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); - $this->type = new VarDateTimeType(); + $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->type = new VarDateTimeType(); + $this->backedUpType = Type::getType(Types::DATETIME_MUTABLE); + Type::getTypeRegistry()->override(Types::DATETIME_MUTABLE, $this->type); + } + + public function tearDown(): void + { + Type::getTypeRegistry()->override( + Types::DATETIME_MUTABLE, + $this->backedUpType + ); } public function testDateTimeConvertsToDatabaseValue(): void