11
11
12
12
namespace Symfony \Bridge \Doctrine \Tests \Types ;
13
13
14
+ use Doctrine \DBAL \Exception ;
14
15
use Doctrine \DBAL \Platforms \AbstractPlatform ;
15
16
use Doctrine \DBAL \Platforms \MariaDBPlatform ;
16
17
use Doctrine \DBAL \Platforms \MySQLPlatform ;
17
18
use Doctrine \DBAL \Platforms \PostgreSQLPlatform ;
18
- use Doctrine \DBAL \Platforms \SQLitePlatform ;
19
19
use Doctrine \DBAL \Types \ConversionException ;
20
20
use Doctrine \DBAL \Types \Type ;
21
21
use PHPUnit \Framework \TestCase ;
22
22
use Symfony \Bridge \Doctrine \Types \UlidType ;
23
23
use Symfony \Component \Uid \AbstractUid ;
24
24
use Symfony \Component \Uid \Ulid ;
25
25
26
- // DBAL 3 compatibility
27
- class_exists ('Doctrine\DBAL\Platforms\SqlitePlatform ' );
28
-
29
- // DBAL 3 compatibility
30
- class_exists ('Doctrine\DBAL\Platforms\SqlitePlatform ' );
31
-
32
26
final class UlidTypeTest extends TestCase
33
27
{
34
28
private const DUMMY_ULID = '01EEDQEK6ZAZE93J8KG5B4MBJC ' ;
@@ -87,25 +81,25 @@ public function testNotSupportedTypeConversionForDatabaseValue()
87
81
{
88
82
$ this ->expectException (ConversionException::class);
89
83
90
- $ this ->type ->convertToDatabaseValue (new \stdClass (), new SQLitePlatform ());
84
+ $ this ->type ->convertToDatabaseValue (new \stdClass (), self :: getSqlitePlatform ());
91
85
}
92
86
93
87
public function testNullConversionForDatabaseValue ()
94
88
{
95
- $ this ->assertNull ($ this ->type ->convertToDatabaseValue (null , new SQLitePlatform ()));
89
+ $ this ->assertNull ($ this ->type ->convertToDatabaseValue (null , self :: getSqlitePlatform ()));
96
90
}
97
91
98
92
public function testUlidInterfaceConvertsToPHPValue ()
99
93
{
100
94
$ ulid = $ this ->createMock (AbstractUid::class);
101
- $ actual = $ this ->type ->convertToPHPValue ($ ulid , new SQLitePlatform ());
95
+ $ actual = $ this ->type ->convertToPHPValue ($ ulid , self :: getSqlitePlatform ());
102
96
103
97
$ this ->assertSame ($ ulid , $ actual );
104
98
}
105
99
106
100
public function testUlidConvertsToPHPValue ()
107
101
{
108
- $ ulid = $ this ->type ->convertToPHPValue (self ::DUMMY_ULID , new SQLitePlatform ());
102
+ $ ulid = $ this ->type ->convertToPHPValue (self ::DUMMY_ULID , self :: getSqlitePlatform ());
109
103
110
104
$ this ->assertInstanceOf (Ulid::class, $ ulid );
111
105
$ this ->assertEquals (self ::DUMMY_ULID , $ ulid ->__toString ());
@@ -115,19 +109,19 @@ public function testInvalidUlidConversionForPHPValue()
115
109
{
116
110
$ this ->expectException (ConversionException::class);
117
111
118
- $ this ->type ->convertToPHPValue ('abcdefg ' , new SQLitePlatform ());
112
+ $ this ->type ->convertToPHPValue ('abcdefg ' , self :: getSqlitePlatform ());
119
113
}
120
114
121
115
public function testNullConversionForPHPValue ()
122
116
{
123
- $ this ->assertNull ($ this ->type ->convertToPHPValue (null , new SQLitePlatform ()));
117
+ $ this ->assertNull ($ this ->type ->convertToPHPValue (null , self :: getSqlitePlatform ()));
124
118
}
125
119
126
120
public function testReturnValueIfUlidForPHPValue ()
127
121
{
128
122
$ ulid = new Ulid ();
129
123
130
- $ this ->assertSame ($ ulid , $ this ->type ->convertToPHPValue ($ ulid , new SQLitePlatform ()));
124
+ $ this ->assertSame ($ ulid , $ this ->type ->convertToPHPValue ($ ulid , self :: getSqlitePlatform ()));
131
125
}
132
126
133
127
public function testGetName ()
@@ -146,13 +140,23 @@ public function testGetGuidTypeDeclarationSQL(AbstractPlatform $platform, string
146
140
public static function provideSqlDeclarations (): \Generator
147
141
{
148
142
yield [new PostgreSQLPlatform (), 'UUID ' ];
149
- yield [new SQLitePlatform (), 'BLOB ' ];
143
+ yield [self :: getSqlitePlatform (), 'BLOB ' ];
150
144
yield [new MySQLPlatform (), 'BINARY(16) ' ];
151
145
yield [new MariaDBPlatform (), 'BINARY(16) ' ];
152
146
}
153
147
154
148
public function testRequiresSQLCommentHint ()
155
149
{
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 ();
157
161
}
158
162
}
0 commit comments