17
17
use Symfony \Component \Messenger \Transport \Doctrine \Connection ;
18
18
19
19
/**
20
- * @requires pdo_mysql
20
+ * @requires extension pdo_sqlite
21
21
*/
22
22
class DoctrineIntegrationTest extends TestCase
23
23
{
24
24
private $ driverConnection ;
25
25
private $ connection ;
26
26
27
- protected function setUp ()
27
+ /**
28
+ * @after
29
+ */
30
+ public function cleanup ()
28
31
{
29
- parent ::setUp ();
32
+ @unlink (sys_get_temp_dir ().'/symfony.messenger.sqlite ' );
33
+ }
30
34
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 ' )]);
33
44
}
34
- $ dsn = getenv ('MESSENGER_DOCTRINE_DSN ' );
35
- $ this ->driverConnection = DriverManager::getConnection (['url ' => $ dsn ]);
36
45
$ this ->connection = new Connection ([], $ this ->driverConnection );
37
46
// call send to auto-setup the table
38
47
$ this ->connection ->setup ();
@@ -62,7 +71,7 @@ public function testSendWithDelay()
62
71
63
72
$ available_at = new \DateTime ($ available_at );
64
73
65
- $ now = \DateTime:: createFromFormat ( ' U.u ' , microtime ( true ) );
74
+ $ now = new \DateTime ( );
66
75
$ now ->modify ('+60 seconds ' );
67
76
$ this ->assertGreaterThan ($ now , $ available_at );
68
77
}
@@ -77,7 +86,7 @@ public function testItRetrieveTheFirstAvailableMessage()
77
86
'queue_name ' => 'default ' ,
78
87
'created_at ' => Connection::formatDateTime (new \DateTime ('2019-03-15 12:00:00 ' )),
79
88
'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 ( )),
81
90
]);
82
91
// one available later
83
92
$ this ->driverConnection ->insert ('messenger_messages ' , [
@@ -110,7 +119,7 @@ public function testItCountMessages()
110
119
'queue_name ' => 'default ' ,
111
120
'created_at ' => Connection::formatDateTime (new \DateTime ('2019-03-15 12:00:00 ' )),
112
121
'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 ( )),
114
123
]);
115
124
// one available later
116
125
$ this ->driverConnection ->insert ('messenger_messages ' , [
0 commit comments