From 0016eda889c7fe71d342369d47fb1e9ecc3a0161 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 13 Jun 2023 09:48:44 -0700 Subject: [PATCH] GetMockForAbstractClass See: https://github.com/sebastianbergmann/phpunit/issues/5241 --- tests/ConnectionTest.php | 4 +-- tests/Functional/Ticket/DBAL461Test.php | 2 +- tests/Types/BaseDateTypeTestCase.php | 2 +- tests/Types/BinaryTest.php | 33 ------------------------- tests/Types/DateTest.php | 3 +++ tests/Types/DateTimeTest.php | 5 +++- tests/Types/DateTimeTzTest.php | 3 +++ tests/Types/TimeTest.php | 3 +++ tests/Types/VarDateTimeTest.php | 2 +- 9 files changed, 18 insertions(+), 39 deletions(-) diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index b4f5c963216..de4df468c18 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -530,7 +530,7 @@ public function testPlatformDetectionFetchedFromParameters(): void $driverConnectionMock = $this->createMock(Driver\Connection::class); - $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); + $platformMock = $this->createMock(AbstractPlatform::class); $connection = new Connection(['serverVersion' => '8.0'], $driverMock); @@ -552,7 +552,7 @@ public function testPlatformDetectionFetchedFromPrimaryReplicaParameters(): void $driverConnectionMock = $this->createMock(Driver\Connection::class); - $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); + $platformMock = $this->createMock(AbstractPlatform::class); $connection = new Connection(['primary' => ['serverVersion' => '8.0']], $driverMock); diff --git a/tests/Functional/Ticket/DBAL461Test.php b/tests/Functional/Ticket/DBAL461Test.php index 5028a9393e8..8b9b122cdd0 100644 --- a/tests/Functional/Ticket/DBAL461Test.php +++ b/tests/Functional/Ticket/DBAL461Test.php @@ -17,7 +17,7 @@ class DBAL461Test extends TestCase public function testIssue(): void { $conn = $this->createMock(Connection::class); - $platform = $this->getMockForAbstractClass(SQLServerPlatform::class); + $platform = new SQLServerPlatform(); $platform->registerDoctrineTypeMapping('numeric', Types::DECIMAL); $schemaManager = new SQLServerSchemaManager($conn, $platform); diff --git a/tests/Types/BaseDateTypeTestCase.php b/tests/Types/BaseDateTypeTestCase.php index 81d6d4dc67b..1fa9fe7a4ac 100644 --- a/tests/Types/BaseDateTypeTestCase.php +++ b/tests/Types/BaseDateTypeTestCase.php @@ -26,7 +26,7 @@ abstract class BaseDateTypeTestCase extends TestCase protected function setUp(): void { - $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->platform = $this->createMock(AbstractPlatform::class); $this->currentTimezone = date_default_timezone_get(); } diff --git a/tests/Types/BinaryTest.php b/tests/Types/BinaryTest.php index d95de474e0a..bdb4093c52b 100644 --- a/tests/Types/BinaryTest.php +++ b/tests/Types/BinaryTest.php @@ -35,39 +35,6 @@ public function testReturnsBindingType(): void self::assertSame(ParameterType::BINARY, $this->type->getBindingType()); } - /** - * @param mixed[][] $definition - * - * @dataProvider definitionProvider() - */ - public function testReturnsSQLDeclaration(array $definition, string $expectedDeclaration): void - { - $platform = $this->getMockForAbstractClass(AbstractPlatform::class); - self::assertSame($expectedDeclaration, $this->type->getSQLDeclaration($definition, $platform)); - } - - /** @return mixed[][] */ - public static function definitionProvider(): iterable - { - return [ - 'fixed-unspecified-length' => [ - ['fixed' => true], - 'BINARY', - ], - 'fixed-specified-length' => [ - [ - 'fixed' => true, - 'length' => 20, - ], - 'BINARY(20)', - ], - 'variable-length' => [ - ['length' => 20], - 'VARBINARY(20)', - ], - ]; - } - public function testBinaryNullConvertsToPHPValue(): void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); diff --git a/tests/Types/DateTest.php b/tests/Types/DateTest.php index 8b4fea1280b..12476b05dd5 100644 --- a/tests/Types/DateTest.php +++ b/tests/Types/DateTest.php @@ -17,6 +17,9 @@ protected function setUp(): void $this->type = new DateType(); parent::setUp(); + + $this->platform->method('getDateFormatString') + ->willReturn('Y-m-d'); } public function testDateConvertsToPHPValue(): void diff --git a/tests/Types/DateTimeTest.php b/tests/Types/DateTimeTest.php index 2814ed75f8e..f2d13739156 100644 --- a/tests/Types/DateTimeTest.php +++ b/tests/Types/DateTimeTest.php @@ -15,13 +15,16 @@ protected function setUp(): void $this->type = new DateTimeType(); parent::setUp(); + + $this->platform->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); } public function testDateTimeConvertsToDatabaseValue(): void { $date = new DateTime('1985-09-01 10:10:10'); - $expected = $date->format($this->platform->getDateTimeTzFormatString()); + $expected = $date->format($this->platform->getDateTimeFormatString()); $actual = $this->type->convertToDatabaseValue($date, $this->platform); self::assertEquals($expected, $actual); diff --git a/tests/Types/DateTimeTzTest.php b/tests/Types/DateTimeTzTest.php index fbcdde15094..d6a9598a5ae 100644 --- a/tests/Types/DateTimeTzTest.php +++ b/tests/Types/DateTimeTzTest.php @@ -15,6 +15,9 @@ protected function setUp(): void $this->type = new DateTimeTzType(); parent::setUp(); + + $this->platform->method('getDateTimeTzFormatString') + ->willReturn('Y-m-d H:i:s'); } public function testDateTimeConvertsToDatabaseValue(): void diff --git a/tests/Types/TimeTest.php b/tests/Types/TimeTest.php index edaed7160a9..cbe8c50caaa 100644 --- a/tests/Types/TimeTest.php +++ b/tests/Types/TimeTest.php @@ -15,6 +15,9 @@ protected function setUp(): void $this->type = new TimeType(); parent::setUp(); + + $this->platform->method('getTimeFormatString') + ->willReturn('H:i:s'); } public function testTimeConvertsToPHPValue(): void diff --git a/tests/Types/VarDateTimeTest.php b/tests/Types/VarDateTimeTest.php index 0eecaba4a7a..472d2fb1cc4 100644 --- a/tests/Types/VarDateTimeTest.php +++ b/tests/Types/VarDateTimeTest.php @@ -20,7 +20,7 @@ class VarDateTimeTest extends TestCase protected function setUp(): void { - $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = new VarDateTimeType(); }