Skip to content

Commit ba77296

Browse files
committed
choose the correctly cased class name for the SQLite platform
1 parent cb47b1a commit ba77296

File tree

3 files changed

+54
-32
lines changed

3 files changed

+54
-32
lines changed

Tests/Types/DatePointTypeTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Types;
1313

14+
use Doctrine\DBAL\Exception;
1415
use Doctrine\DBAL\Platforms\AbstractPlatform;
15-
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1616
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
17-
use Doctrine\DBAL\Platforms\SqlitePlatform;
18-
use Doctrine\DBAL\Types\ConversionException;
1917
use Doctrine\DBAL\Types\Type;
2018
use PHPUnit\Framework\TestCase;
2119
use Symfony\Bridge\Doctrine\Types\DatePointType;
@@ -56,14 +54,14 @@ public function testDatePointConvertsToDatabaseValue()
5654
public function testDatePointConvertsToPHPValue()
5755
{
5856
$datePoint = new DatePoint();
59-
$actual = $this->type->convertToPHPValue($datePoint, new SqlitePlatform());
57+
$actual = $this->type->convertToPHPValue($datePoint, self::getSqlitePlatform());
6058

6159
$this->assertSame($datePoint, $actual);
6260
}
6361

6462
public function testNullConvertsToPHPValue()
6563
{
66-
$actual = $this->type->convertToPHPValue(null, new SqlitePlatform());
64+
$actual = $this->type->convertToPHPValue(null, self::getSqlitePlatform());
6765

6866
$this->assertNull($actual);
6967
}
@@ -72,7 +70,7 @@ public function testDateTimeImmutableConvertsToPHPValue()
7270
{
7371
$format = 'Y-m-d H:i:s';
7472
$dateTime = new \DateTimeImmutable('2025-03-03 12:13:14');
75-
$actual = $this->type->convertToPHPValue($dateTime, new SqlitePlatform());
73+
$actual = $this->type->convertToPHPValue($dateTime, self::getSqlitePlatform());
7674
$expected = DatePoint::createFromInterface($dateTime);
7775

7876
$this->assertSame($expected->format($format), $actual->format($format));
@@ -82,4 +80,14 @@ public function testGetName()
8280
{
8381
$this->assertSame('date_point', $this->type->getName());
8482
}
83+
84+
private static function getSqlitePlatform(): AbstractPlatform
85+
{
86+
if (interface_exists(Exception::class)) {
87+
// DBAL 4+
88+
return new \Doctrine\DBAL\Platforms\SQLitePlatform();
89+
}
90+
91+
return new \Doctrine\DBAL\Platforms\SqlitePlatform();
92+
}
8593
}

Tests/Types/UlidTypeTest.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Types;
1313

14+
use Doctrine\DBAL\Exception;
1415
use Doctrine\DBAL\Platforms\AbstractPlatform;
1516
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1617
use Doctrine\DBAL\Platforms\MySQLPlatform;
1718
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
18-
use Doctrine\DBAL\Platforms\SQLitePlatform;
1919
use Doctrine\DBAL\Types\ConversionException;
2020
use Doctrine\DBAL\Types\Type;
2121
use PHPUnit\Framework\TestCase;
2222
use Symfony\Bridge\Doctrine\Types\UlidType;
2323
use Symfony\Component\Uid\AbstractUid;
2424
use Symfony\Component\Uid\Ulid;
2525

26-
// DBAL 3 compatibility
27-
class_exists('Doctrine\DBAL\Platforms\SqlitePlatform');
28-
29-
// DBAL 3 compatibility
30-
class_exists('Doctrine\DBAL\Platforms\SqlitePlatform');
31-
3226
final class UlidTypeTest extends TestCase
3327
{
3428
private const DUMMY_ULID = '01EEDQEK6ZAZE93J8KG5B4MBJC';
@@ -87,25 +81,25 @@ public function testNotSupportedTypeConversionForDatabaseValue()
8781
{
8882
$this->expectException(ConversionException::class);
8983

90-
$this->type->convertToDatabaseValue(new \stdClass(), new SQLitePlatform());
84+
$this->type->convertToDatabaseValue(new \stdClass(), self::getSqlitePlatform());
9185
}
9286

9387
public function testNullConversionForDatabaseValue()
9488
{
95-
$this->assertNull($this->type->convertToDatabaseValue(null, new SQLitePlatform()));
89+
$this->assertNull($this->type->convertToDatabaseValue(null, self::getSqlitePlatform()));
9690
}
9791

9892
public function testUlidInterfaceConvertsToPHPValue()
9993
{
10094
$ulid = $this->createMock(AbstractUid::class);
101-
$actual = $this->type->convertToPHPValue($ulid, new SQLitePlatform());
95+
$actual = $this->type->convertToPHPValue($ulid, self::getSqlitePlatform());
10296

10397
$this->assertSame($ulid, $actual);
10498
}
10599

106100
public function testUlidConvertsToPHPValue()
107101
{
108-
$ulid = $this->type->convertToPHPValue(self::DUMMY_ULID, new SQLitePlatform());
102+
$ulid = $this->type->convertToPHPValue(self::DUMMY_ULID, self::getSqlitePlatform());
109103

110104
$this->assertInstanceOf(Ulid::class, $ulid);
111105
$this->assertEquals(self::DUMMY_ULID, $ulid->__toString());
@@ -115,19 +109,19 @@ public function testInvalidUlidConversionForPHPValue()
115109
{
116110
$this->expectException(ConversionException::class);
117111

118-
$this->type->convertToPHPValue('abcdefg', new SQLitePlatform());
112+
$this->type->convertToPHPValue('abcdefg', self::getSqlitePlatform());
119113
}
120114

121115
public function testNullConversionForPHPValue()
122116
{
123-
$this->assertNull($this->type->convertToPHPValue(null, new SQLitePlatform()));
117+
$this->assertNull($this->type->convertToPHPValue(null, self::getSqlitePlatform()));
124118
}
125119

126120
public function testReturnValueIfUlidForPHPValue()
127121
{
128122
$ulid = new Ulid();
129123

130-
$this->assertSame($ulid, $this->type->convertToPHPValue($ulid, new SQLitePlatform()));
124+
$this->assertSame($ulid, $this->type->convertToPHPValue($ulid, self::getSqlitePlatform()));
131125
}
132126

133127
public function testGetName()
@@ -146,13 +140,23 @@ public function testGetGuidTypeDeclarationSQL(AbstractPlatform $platform, string
146140
public static function provideSqlDeclarations(): \Generator
147141
{
148142
yield [new PostgreSQLPlatform(), 'UUID'];
149-
yield [new SQLitePlatform(), 'BLOB'];
143+
yield [self::getSqlitePlatform(), 'BLOB'];
150144
yield [new MySQLPlatform(), 'BINARY(16)'];
151145
yield [new MariaDBPlatform(), 'BINARY(16)'];
152146
}
153147

154148
public function testRequiresSQLCommentHint()
155149
{
156-
$this->assertTrue($this->type->requiresSQLCommentHint(new SQLitePlatform()));
150+
$this->assertTrue($this->type->requiresSQLCommentHint(self::getSqlitePlatform()));
151+
}
152+
153+
private static function getSqlitePlatform(): AbstractPlatform
154+
{
155+
if (interface_exists(Exception::class)) {
156+
// DBAL 4+
157+
return new \Doctrine\DBAL\Platforms\SQLitePlatform();
158+
}
159+
160+
return new \Doctrine\DBAL\Platforms\SqlitePlatform();
157161
}
158162
}

Tests/Types/UuidTypeTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Types;
1313

14+
use Doctrine\DBAL\Exception;
1415
use Doctrine\DBAL\Platforms\AbstractPlatform;
1516
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1617
use Doctrine\DBAL\Platforms\MySQLPlatform;
1718
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
18-
use Doctrine\DBAL\Platforms\SqlitePlatform;
1919
use Doctrine\DBAL\Types\ConversionException;
2020
use Doctrine\DBAL\Types\Type;
2121
use PHPUnit\Framework\TestCase;
@@ -92,25 +92,25 @@ public function testNotSupportedTypeConversionForDatabaseValue()
9292
{
9393
$this->expectException(ConversionException::class);
9494

95-
$this->type->convertToDatabaseValue(new \stdClass(), new SqlitePlatform());
95+
$this->type->convertToDatabaseValue(new \stdClass(), self::getSqlitePlatform());
9696
}
9797

9898
public function testNullConversionForDatabaseValue()
9999
{
100-
$this->assertNull($this->type->convertToDatabaseValue(null, new SqlitePlatform()));
100+
$this->assertNull($this->type->convertToDatabaseValue(null, self::getSqlitePlatform()));
101101
}
102102

103103
public function testUuidInterfaceConvertsToPHPValue()
104104
{
105105
$uuid = $this->createMock(AbstractUid::class);
106-
$actual = $this->type->convertToPHPValue($uuid, new SqlitePlatform());
106+
$actual = $this->type->convertToPHPValue($uuid, self::getSqlitePlatform());
107107

108108
$this->assertSame($uuid, $actual);
109109
}
110110

111111
public function testUuidConvertsToPHPValue()
112112
{
113-
$uuid = $this->type->convertToPHPValue(self::DUMMY_UUID, new SqlitePlatform());
113+
$uuid = $this->type->convertToPHPValue(self::DUMMY_UUID, self::getSqlitePlatform());
114114

115115
$this->assertInstanceOf(Uuid::class, $uuid);
116116
$this->assertEquals(self::DUMMY_UUID, $uuid->__toString());
@@ -120,19 +120,19 @@ public function testInvalidUuidConversionForPHPValue()
120120
{
121121
$this->expectException(ConversionException::class);
122122

123-
$this->type->convertToPHPValue('abcdefg', new SqlitePlatform());
123+
$this->type->convertToPHPValue('abcdefg', self::getSqlitePlatform());
124124
}
125125

126126
public function testNullConversionForPHPValue()
127127
{
128-
$this->assertNull($this->type->convertToPHPValue(null, new SqlitePlatform()));
128+
$this->assertNull($this->type->convertToPHPValue(null, self::getSqlitePlatform()));
129129
}
130130

131131
public function testReturnValueIfUuidForPHPValue()
132132
{
133133
$uuid = Uuid::v4();
134134

135-
$this->assertSame($uuid, $this->type->convertToPHPValue($uuid, new SqlitePlatform()));
135+
$this->assertSame($uuid, $this->type->convertToPHPValue($uuid, self::getSqlitePlatform()));
136136
}
137137

138138
public function testGetName()
@@ -151,13 +151,23 @@ public function testGetGuidTypeDeclarationSQL(AbstractPlatform $platform, string
151151
public static function provideSqlDeclarations(): \Generator
152152
{
153153
yield [new PostgreSQLPlatform(), 'UUID'];
154-
yield [new SqlitePlatform(), 'BLOB'];
154+
yield [self::getSqlitePlatform(), 'BLOB'];
155155
yield [new MySQLPlatform(), 'BINARY(16)'];
156156
yield [new MariaDBPlatform(), 'BINARY(16)'];
157157
}
158158

159159
public function testRequiresSQLCommentHint()
160160
{
161-
$this->assertTrue($this->type->requiresSQLCommentHint(new SqlitePlatform()));
161+
$this->assertTrue($this->type->requiresSQLCommentHint(self::getSqlitePlatform()));
162+
}
163+
164+
private static function getSqlitePlatform(): AbstractPlatform
165+
{
166+
if (interface_exists(Exception::class)) {
167+
// DBAL 4+
168+
return new \Doctrine\DBAL\Platforms\SQLitePlatform();
169+
}
170+
171+
return new \Doctrine\DBAL\Platforms\SqlitePlatform();
162172
}
163173
}

0 commit comments

Comments
 (0)