Skip to content

Commit

Permalink
Rework the tests using TestCase::getMockForAbstractClass()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jun 14, 2023
1 parent 800be40 commit 1dc87d0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ public function testPlatformDetectionFetchedFromParameters(): void

$driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class);

$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);
$platformMock = $this->createMock(AbstractPlatform::class);

$connection = new Connection(['serverVersion' => '8.0'], $driverMock);

Expand All @@ -767,7 +767,7 @@ public function testPlatformDetectionFetchedFromPrimaryReplicaParameters(): void

$driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class);

$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);
$platformMock = $this->createMock(AbstractPlatform::class);

$connection = new Connection(['primary' => ['serverVersion' => '8.0']], $driverMock);

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Ticket/DBAL461Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DBAL461Test extends TestCase
public function testIssue(): void
{
$conn = $this->createMock(Connection::class);
$platform = $this->getMockForAbstractClass(SQLServer2012Platform::class);
$platform = new SQLServer2012Platform();
$platform->registerDoctrineTypeMapping('numeric', Types::DECIMAL);

$schemaManager = new SQLServerSchemaManager($conn, $platform);
Expand Down
2 changes: 1 addition & 1 deletion tests/Types/BaseDateTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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();

self::assertInstanceOf(Type::class, $this->type);
Expand Down
3 changes: 3 additions & 0 deletions tests/Types/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ protected function setUp(): void
$this->type = new DateType();

parent::setUp();

$this->platform->method('getDateFormatString')
->willReturn('Y-m-d');
}

public function testDateConvertsToPHPValue(): void
Expand Down
5 changes: 4 additions & 1 deletion tests/Types/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,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);
Expand Down
3 changes: 3 additions & 0 deletions tests/Types/DateTimeTzTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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
Expand Down
3 changes: 3 additions & 0 deletions tests/Types/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ protected function setUp(): void
$this->type = new TimeType();

parent::setUp();

$this->platform->method('getTimeFormatString')
->willReturn('H:i:s');
}

public function testTimeConvertsToPHPValue(): void
Expand Down
7 changes: 5 additions & 2 deletions tests/Types/VarDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ class VarDateTimeTest extends TestCase

protected function setUp(): void
{
$this->platform = $this->getMockForAbstractClass(AbstractPlatform::class);
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new VarDateTimeType();

$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);
Expand Down

0 comments on commit 1dc87d0

Please sign in to comment.