18
18
use Doctrine \DBAL \DriverManager ;
19
19
use Doctrine \DBAL \Schema \DefaultSchemaManagerFactory ;
20
20
use Doctrine \DBAL \Schema \Schema ;
21
- use PHPUnit \Framework \SkippedTestSuiteError ;
22
21
use Psr \Cache \CacheItemPoolInterface ;
23
22
use Symfony \Component \Cache \Adapter \DoctrineDbalAdapter ;
24
23
use Symfony \Component \Cache \Tests \Fixtures \DriverWrapper ;
25
24
26
25
/**
26
+ * @requires extension pdo_sqlite
27
+ *
27
28
* @group time-sensitive
28
29
*/
29
30
class DoctrineDbalAdapterTest extends AdapterTestCase
@@ -32,10 +33,6 @@ class DoctrineDbalAdapterTest extends AdapterTestCase
32
33
33
34
public static function setUpBeforeClass (): void
34
35
{
35
- if (!\extension_loaded ('pdo_sqlite ' )) {
36
- throw new SkippedTestSuiteError ('Extension pdo_sqlite required. ' );
37
- }
38
-
39
36
self ::$ dbFile = tempnam (sys_get_temp_dir (), 'sf_sqlite_cache ' );
40
37
}
41
38
@@ -107,13 +104,12 @@ public function testConfigureSchemaTableExists()
107
104
}
108
105
109
106
/**
110
- * @dataProvider provideDsn
107
+ * @dataProvider provideDsnWithSQLite
111
108
*/
112
- public function testDsn (string $ dsn , string $ file = null )
109
+ public function testDsnWithSQLite (string $ dsn , string $ file = null )
113
110
{
114
111
try {
115
112
$ pool = new DoctrineDbalAdapter ($ dsn );
116
- $ pool ->createTable ();
117
113
118
114
$ item = $ pool ->getItem ('key ' );
119
115
$ item ->set ('value ' );
@@ -125,12 +121,35 @@ public function testDsn(string $dsn, string $file = null)
125
121
}
126
122
}
127
123
128
- public static function provideDsn ()
124
+ public static function provideDsnWithSQLite ()
129
125
{
130
126
$ dbFile = tempnam (sys_get_temp_dir (), 'sf_sqlite_cache ' );
131
- yield ['sqlite://localhost/ ' .$ dbFile .'1 ' , $ dbFile .'1 ' ];
132
- yield ['sqlite3:/// ' .$ dbFile .'3 ' , $ dbFile .'3 ' ];
133
- yield ['sqlite://localhost/:memory: ' ];
127
+ yield 'SQLite file ' => ['sqlite://localhost/ ' .$ dbFile .'1 ' , $ dbFile .'1 ' ];
128
+ yield 'SQLite3 file ' => ['sqlite3:/// ' .$ dbFile .'3 ' , $ dbFile .'3 ' ];
129
+ yield 'SQLite in memory ' => ['sqlite://localhost/:memory: ' ];
130
+ }
131
+
132
+ /**
133
+ * @requires extension pdo_pgsql
134
+ *
135
+ * @group integration
136
+ */
137
+ public function testDsnWithPostgreSQL ()
138
+ {
139
+ if (!$ host = getenv ('POSTGRES_HOST ' )) {
140
+ $ this ->markTestSkipped ('Missing POSTGRES_HOST env variable ' );
141
+ }
142
+
143
+ try {
144
+ $ pool = new DoctrineDbalAdapter ('pgsql://postgres:password@ ' .$ host );
145
+
146
+ $ item = $ pool ->getItem ('key ' );
147
+ $ item ->set ('value ' );
148
+ $ this ->assertTrue ($ pool ->save ($ item ));
149
+ } finally {
150
+ $ pdo = new \PDO ('pgsql:host= ' .$ host .';user=postgres;password=password ' );
151
+ $ pdo ->exec ('DROP TABLE IF EXISTS cache_items ' );
152
+ }
134
153
}
135
154
136
155
protected function isPruned (DoctrineDbalAdapter $ cache , string $ name ): bool
0 commit comments