Skip to content

Commit

Permalink
qa: move test into dedicated script which is executed from unit test
Browse files Browse the repository at this point in the history
This reduces the number of Docker containers spun up during CI and results in fewer total checks.

Signed-off-by: Maximilian Bösing <[email protected]>
  • Loading branch information
boesing committed Jul 10, 2024
1 parent 3fd0ccc commit eee255b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 49 deletions.
10 changes: 0 additions & 10 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
{
"additional_checks": [
{
"name": "Unit tests with non existent TMPDIR",
"job": {
"php": "*",
"dependencies": "locked",
"command": "TMPDIR=nonexistent vendor/bin/phpunit test/unit/FilesystemOptionsNonExistentTmpdirTest.php"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

require_once dirname(__DIR__, 4) . '/vendor/autoload.php';
use Laminas\Cache\Storage\Adapter\FilesystemOptions;

$option = new FilesystemOptions(['cacheDir' => '/./tmp']);
echo $option->getCacheDir();
39 changes: 0 additions & 39 deletions test/unit/FilesystemOptionsNonExistentTmpdirTest.php

This file was deleted.

28 changes: 28 additions & 0 deletions test/unit/FilesystemOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
use const DIRECTORY_SEPARATOR;
use const PHP_EOL;
use const PHP_OS;
use const PHP_OS_FAMILY;

/**
* @template-extends AbstractAdapterOptionsTest<FilesystemOptions>
*/
final class FilesystemOptionsTest extends AbstractAdapterOptionsTest
{
private const MACOS_FAMILY = 'Darwin';

/** @var string */
protected $keyPattern = FilesystemOptions::KEY_PATTERN;

Expand Down Expand Up @@ -236,4 +239,29 @@ public function testTagSuffixIsMutable(): void
$this->options->setTagSuffix('.cache');
self::assertSame('.cache', $this->options->getTagSuffix());
}

/**
* The test asset script does provide a temporary directory and thus, the nonexistent system temp dir should
* not be used at all.
*/
public function testFilesystemOptionsInstantiationWithNonExistentSystemTemporaryDirectory(): void
{
/**
* Due to the usage of `realpath` {@see FilesystemOptions::normalizeCacheDirectory()}, the directory is changed
* depending on the host system. As there might be developers using MacOS brew PHP to execute these tests, we
* allow MacOS `/private/tmp` as well.
*/
$expectedTemporaryDirectory = match (PHP_OS_FAMILY) {
default => '/tmp',
self::MACOS_FAMILY => '/private/tmp',
};

$cacheDirectoryFromOptions = exec(
'TMPDIR=nonexistent php test/unit/Filesystem/TestAsset/instantiate_filesystem_options_with_cache_dir.php',
$output,
$exitCode,
);
self::assertSame(0, $exitCode);
self::assertSame($expectedTemporaryDirectory, $cacheDirectoryFromOptions);
}
}

0 comments on commit eee255b

Please sign in to comment.