Skip to content

Commit

Permalink
Do not test sys_tmp_dir if cache dir is provied. Fix laminas#65.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcremer committed Jan 29, 2024
1 parent 924a6ab commit f725564
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
6 changes: 4 additions & 2 deletions src/FilesystemOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/unit/FilesystemOptionsNonExistentTmpdirTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Cache\Storage\Adapter;

use Laminas\Cache\Storage\Adapter\FilesystemOptions;
use PHPUnit\Framework\TestCase;

final class FilesystemOptionsNonExistentTmpdirTest extends Testcase
{
public function testWillNotWriteToSystemTempWhenCacheDirIsProvided()
{
if (is_writable(sys_get_temp_dir())) {
self::markTestSkipped('Test has to be executed with a non existent TMPDIR');
}

$option = new FilesystemOptions(['cacheDir' => '/./tmp']);
self::assertSame('/tmp', $option->getCacheDir());
}
}
6 changes: 6 additions & 0 deletions test/unit/FilesystemOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f725564

Please sign in to comment.