diff --git a/.laminas-ci.json b/.laminas-ci.json index 2c63c08..61106fc 100644 --- a/.laminas-ci.json +++ b/.laminas-ci.json @@ -1,2 +1,12 @@ { + "additional_checks": [ + { + "name": "Unit tests with non existent TMPDIR", + "job": { + "php": "*", + "dependencies": "locked", + "command": "TMPDIR=nonexistent vendor/bin/phpunit test/unit/FilesystemOptionsNonExistentTmpdirTest.php" + } + } + ] } diff --git a/src/FilesystemOptions.php b/src/FilesystemOptions.php index e849b8d..8b78304 100644 --- a/src/FilesystemOptions.php +++ b/src/FilesystemOptions.php @@ -112,9 +112,11 @@ public function __construct($options = null) $this->dirPermission = false; } - $this->setCacheDir(null); - parent::__construct($options); + + if ($this->cacheDir === null) { + $this->setCacheDir(null); + } } /** diff --git a/test/unit/FilesystemOptionsNonExistentTmpdirTest.php b/test/unit/FilesystemOptionsNonExistentTmpdirTest.php new file mode 100644 index 0000000..47ca245 --- /dev/null +++ b/test/unit/FilesystemOptionsNonExistentTmpdirTest.php @@ -0,0 +1,21 @@ + '/./tmp']); + self::assertSame('/tmp', $option->getCacheDir()); + } +} diff --git a/test/unit/FilesystemOptionsTest.php b/test/unit/FilesystemOptionsTest.php index 980bad2..45f6f81 100644 --- a/test/unit/FilesystemOptionsTest.php +++ b/test/unit/FilesystemOptionsTest.php @@ -55,6 +55,12 @@ protected function createAdapterOptions(): AdapterOptions return new FilesystemOptions(); } + public function testSetCacheDirToSystemsTempDirWhenNoCacheDirIsProvided(): void + { + $options = new FilesystemOptions(); + self::assertEquals(realpath(sys_get_temp_dir()), $options->getCacheDir()); + } + public function testSetCacheDirToSystemsTempDirWithNull(): void { $this->options->setCacheDir(null);