File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
src/Symfony/Component/Lock Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,12 @@ public function __construct(string $lockPath = null)
4242 if (null === $ lockPath ) {
4343 $ lockPath = sys_get_temp_dir ();
4444 }
45- if (!is_dir ($ lockPath ) || !is_writable ($ lockPath )) {
46- throw new InvalidArgumentException (sprintf ('The directory "%s" is not writable. ' , $ lockPath ));
45+ if (!is_dir ($ lockPath )) {
46+ if (false === @mkdir ($ lockPath , 0777 , true ) && !is_dir ($ lockPath )) {
47+ throw new InvalidArgumentException (sprintf ('The FlockStore directory "%s" does not exists and cannot be created. ' , $ lockPath ));
48+ }
49+ } elseif (!is_writable ($ lockPath )) {
50+ throw new InvalidArgumentException (sprintf ('The FlockStore directory "%s" is not writable. ' , $ lockPath ));
4751 }
4852
4953 $ this ->lockPath = $ lockPath ;
Original file line number Diff line number Diff line change @@ -32,10 +32,10 @@ protected function getStore(): PersistingStoreInterface
3232 return new FlockStore ();
3333 }
3434
35- public function testConstructWhenRepositoryDoesNotExist ()
35+ public function testConstructWhenRepositoryCannotBeCreated ()
3636 {
3737 $ this ->expectException ('Symfony\Component\Lock\Exception\InvalidArgumentException ' );
38- $ this ->expectExceptionMessage ('The directory "/a/b/c/d/e" is not writable . ' );
38+ $ this ->expectExceptionMessage ('The FlockStore directory "/a/b/c/d/e" does not exists and cannot be created . ' );
3939 if (!getenv ('USER ' ) || 'root ' === getenv ('USER ' )) {
4040 $ this ->markTestSkipped ('This test will fail if run under superuser ' );
4141 }
@@ -46,14 +46,23 @@ public function testConstructWhenRepositoryDoesNotExist()
4646 public function testConstructWhenRepositoryIsNotWriteable ()
4747 {
4848 $ this ->expectException ('Symfony\Component\Lock\Exception\InvalidArgumentException ' );
49- $ this ->expectExceptionMessage ('The directory "/" is not writable. ' );
49+ $ this ->expectExceptionMessage ('The FlockStore directory "/" is not writable. ' );
5050 if (!getenv ('USER ' ) || 'root ' === getenv ('USER ' )) {
5151 $ this ->markTestSkipped ('This test will fail if run under superuser ' );
5252 }
5353
5454 new FlockStore ('/ ' );
5555 }
5656
57+ public function testConstructWithSubdir ()
58+ {
59+ if (!getenv ('USER ' ) || 'root ' === getenv ('USER ' )) {
60+ $ this ->markTestSkipped ('This test will fail if run under superuser ' );
61+ }
62+
63+ new FlockStore (\sys_get_temp_dir ().'/sf-flock ' );
64+ }
65+
5766 public function testSaveSanitizeName ()
5867 {
5968 $ store = $ this ->getStore ();
You can’t perform that action at this time.
0 commit comments