Skip to content

Commit 7f94368

Browse files
authored
Merge pull request #78 from php-enqueue/fs-transport-should-create-storage-dir
[fs] Filesystem transport must create a storage dir if it does not exists.
2 parents 8a5305b + bb319dc commit 7f94368

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pkg/fs/FsContext.php

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Enqueue\Psr\PsrDestination;
88
use Enqueue\Psr\PsrQueue;
99
use Makasim\File\TempFile;
10+
use Symfony\Component\Filesystem\Filesystem;
1011
use Symfony\Component\Filesystem\LockHandler;
1112

1213
class FsContext implements PsrContext
@@ -38,6 +39,9 @@ class FsContext implements PsrContext
3839
*/
3940
public function __construct($storeDir, $preFetchCount, $chmod)
4041
{
42+
$fs = new Filesystem();
43+
$fs->mkdir($storeDir);
44+
4145
$this->storeDir = $storeDir;
4246
$this->preFetchCount = $preFetchCount;
4347
$this->chmod = $chmod;
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Enqueue\Fs\Tests\Functional;
4+
5+
use Enqueue\Fs\FsConnectionFactory;
6+
use PHPUnit\Framework\TestCase;
7+
use Symfony\Component\Filesystem\Filesystem;
8+
9+
class FsContextTest extends TestCase
10+
{
11+
public function tearDown()
12+
{
13+
$fs = new Filesystem();
14+
$fs->remove(sys_get_temp_dir().'/enqueue');
15+
}
16+
17+
public function testShouldCreateFoldersIfNotExistOnConstruct()
18+
{
19+
$fs = new Filesystem();
20+
$fs->remove(sys_get_temp_dir().'/enqueue');
21+
22+
$this->fsContext = (new FsConnectionFactory(['store_dir' => sys_get_temp_dir().'/enqueue/dir/notexiststest']))->createContext();
23+
24+
$this->assertDirectoryExists(sys_get_temp_dir().'/enqueue/dir/notexiststest');
25+
}
26+
}

0 commit comments

Comments
 (0)