@@ -12,20 +12,21 @@ class FileProviderTest extends \PHPUnit_Framework_TestCase
1212{
1313 /** @var FileProvider */
1414 protected $ provider ;
15- protected $ path ;
15+ protected $ basePath ;
16+ protected $ queueHash ;
1617 protected $ umask ;
1718
1819 public function setUp ()
1920 {
2021 $ this ->umask = umask (0 );
21- $ this ->path = rtrim (sys_get_temp_dir (), DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR .time ().rand (0 , 1000 );
22- mkdir ($ this ->path );
22+ $ this ->basePath = rtrim (sys_get_temp_dir (), DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR .time ().rand (0 , 1000 );
23+ mkdir ($ this ->basePath );
2324 $ this ->provider = $ this ->getFileProvider ();
2425 }
2526
2627 public function tearDown ()
2728 {
28- $ this ->clean ($ this ->path );
29+ $ this ->clean ($ this ->basePath );
2930 umask ($ this ->umask );
3031 }
3132
@@ -50,7 +51,7 @@ private function getFileProvider(array $options = [])
5051 {
5152 $ options = array_merge (
5253 [
53- 'path ' => $ this ->path ,
54+ 'path ' => $ this ->basePath ,
5455 'logging_enabled ' => false ,
5556 'message_delay ' => 0 ,
5657 'message_timeout ' => 30 ,
@@ -70,6 +71,8 @@ private function getFileProvider(array $options = [])
7071 'Symfony\Bridge\Monolog\Logger ' , [], ['qpush.test ' ]
7172 );
7273
74+ $ this ->queueHash = str_replace ('- ' , '' , md5 ('test ' ));
75+
7376 return new FileProvider ('test ' , $ options , null , $ cache , $ logger );
7477 }
7578
@@ -83,18 +86,19 @@ public function testGetProvider()
8386 public function testCreate ()
8487 {
8588 $ this ->assertTrue ($ this ->provider ->create ());
86- $ this ->assertTrue (is_readable ($ this ->path ));
87- $ this ->assertTrue (is_writable ($ this ->path ));
89+ $ this ->assertTrue (is_readable ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash ));
90+ $ this ->assertTrue (is_writable ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash ));
8891 }
8992
9093 public function testDestroy ()
9194 {
9295 $ this ->provider ->destroy ();
93- $ this ->assertFalse (is_dir ($ this ->path ));
96+ $ this ->assertFalse (is_dir ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash ));
9497 }
9598
9699 public function testReceive ()
97100 {
101+ $ this ->provider ->create ();
98102 $ this ->assertTrue (is_array ($ this ->provider ->receive ()));
99103 }
100104
@@ -103,8 +107,8 @@ public function testDelete()
103107 $ this ->provider ->create ();
104108
105109 $ path = substr (hash ('md5 ' , '123 ' ), 0 , 3 );
106- mkdir ($ this ->path .DIRECTORY_SEPARATOR .$ path );
107- touch ($ this ->path .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .'123.json ' );
110+ mkdir ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash .DIRECTORY_SEPARATOR .$ path );
111+ touch ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .'123.json ' );
108112
109113 $ messages = $ this ->provider ->receive ();
110114 $ this ->assertNotEmpty ($ messages );
@@ -113,6 +117,7 @@ public function testDelete()
113117
114118 public function testPublish ()
115119 {
120+ $ this ->provider ->create ();
116121 $ content = [
117122 ['testing ' ],
118123 ['testing 123 ' ]
@@ -129,6 +134,7 @@ public function testPublish()
129134 }
130135
131136 public function testPublishDelay () {
137+ $ this ->provider ->create ();
132138 $ provider = $ this ->getFileProvider ([
133139 'message_delay ' => 2 ,
134140 ]);
@@ -142,16 +148,17 @@ public function testOnMessageReceived()
142148 $ this ->provider ->create ();
143149 $ id = $ this ->provider ->publish (['foo ' => 'bar ' ]);
144150 $ path = substr (hash ('md5 ' , $ id ), 0 , 3 );
145- $ this ->assertTrue (is_file ($ this ->path .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .$ id .'.json ' ));
151+ $ this ->assertTrue (is_file ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .$ id .'.json ' ));
146152 $ this ->provider ->onMessageReceived (new MessageEvent (
147153 'test ' ,
148154 $ this ->provider ->receive ()[0 ]
149155 ));
150- $ this ->assertFalse (is_file ($ this ->path .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .$ id .'.json ' ));
156+ $ this ->assertFalse (is_file ($ this ->basePath . DIRECTORY_SEPARATOR . $ this -> queueHash .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .$ id .'.json ' ));
151157 }
152158
153159 public function testCleanUp ()
154160 {
161+ $ this ->provider ->create ();
155162 $ provider = $ this ->getFileProvider ([
156163 'message_expiration ' => 1 ,
157164 ]);
0 commit comments