Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not test sys_tmp_dir if cache dir is provided. Fix #65. #84

Open
wants to merge 1 commit into
base: 2.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a whole CI run, can we have a single test that uses exec on a dummy script, perhaps? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you expect that test to check the exit code or how do we ensure that exactly the non-writable directory leads to the issue and not something else?

{
"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
24 changes: 24 additions & 0 deletions test/unit/FilesystemOptionsNonExistentTmpdirTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Cache\Storage\Adapter;

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

use function is_writable;
use function sys_get_temp_dir;

final class FilesystemOptionsNonExistentTmpdirTest extends TestCase
{
public function testWillNotWriteToSystemTempWhenCacheDirIsProvided(): void
{
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