1717use Symfony \Component \Messenger \Transport \Doctrine \Connection ;
1818
1919/**
20- * @requires pdo_mysql
20+ * @requires extension pdo_sqlite
2121 */
2222class DoctrineIntegrationTest extends TestCase
2323{
2424 private $ driverConnection ;
2525 private $ connection ;
2626
27- protected function setUp ()
27+ /**
28+ * @after
29+ */
30+ public function cleanup ()
2831 {
29- parent ::setUp ();
32+ @unlink (sys_get_temp_dir ().'/symfony.messenger.sqlite ' );
33+ }
3034
31- if (!getenv ('MESSENGER_DOCTRINE_DSN ' )) {
32- $ this ->markTestSkipped ('The "MESSENGER_DOCTRINE_DSN" environment variable is required. ' );
35+ /**
36+ * @before
37+ */
38+ public function createConnection ()
39+ {
40+ if ($ dsn = getenv ('MESSENGER_DOCTRINE_DSN ' )) {
41+ $ this ->driverConnection = DriverManager::getConnection (['url ' => $ dsn ]);
42+ } else {
43+ $ this ->driverConnection = DriverManager::getConnection (['pdo ' => new \PDO ('sqlite: ' .sys_get_temp_dir ().'/symfony.messenger.sqlite ' )]);
3344 }
34- $ dsn = getenv ('MESSENGER_DOCTRINE_DSN ' );
35- $ this ->driverConnection = DriverManager::getConnection (['url ' => $ dsn ]);
3645 $ this ->connection = new Connection ([], $ this ->driverConnection );
3746 // call send to auto-setup the table
3847 $ this ->connection ->setup ();
@@ -62,7 +71,7 @@ public function testSendWithDelay()
6271
6372 $ available_at = new \DateTime ($ available_at );
6473
65- $ now = \DateTime:: createFromFormat ( ' U.u ' , microtime ( true ) );
74+ $ now = new \DateTime ( );
6675 $ now ->modify ('+60 seconds ' );
6776 $ this ->assertGreaterThan ($ now , $ available_at );
6877 }
@@ -77,7 +86,7 @@ public function testItRetrieveTheFirstAvailableMessage()
7786 'queue_name ' => 'default ' ,
7887 'created_at ' => Connection::formatDateTime (new \DateTime ('2019-03-15 12:00:00 ' )),
7988 'available_at ' => Connection::formatDateTime (new \DateTime ('2019-03-15 12:00:00 ' )),
80- 'delivered_at ' => Connection::formatDateTime (\DateTime:: createFromFormat ( ' U.u ' , microtime ( true ) )),
89+ 'delivered_at ' => Connection::formatDateTime (new \DateTime ( )),
8190 ]);
8291 // one available later
8392 $ this ->driverConnection ->insert ('messenger_messages ' , [
@@ -110,7 +119,7 @@ public function testItCountMessages()
110119 'queue_name ' => 'default ' ,
111120 'created_at ' => Connection::formatDateTime (new \DateTime ('2019-03-15 12:00:00 ' )),
112121 'available_at ' => Connection::formatDateTime (new \DateTime ('2019-03-15 12:00:00 ' )),
113- 'delivered_at ' => Connection::formatDateTime (\DateTime:: createFromFormat ( ' U.u ' , microtime ( true ) )),
122+ 'delivered_at ' => Connection::formatDateTime (new \DateTime ( )),
114123 ]);
115124 // one available later
116125 $ this ->driverConnection ->insert ('messenger_messages ' , [
0 commit comments