Skip to content

Commit

Permalink
Use path of configuration or executable to pin result cache in place
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden authored and sebastianbergmann committed Apr 27, 2019
1 parent 12db416 commit 795abc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/Runner/DefaultTestResultCache.php
Expand Up @@ -66,9 +66,14 @@ final class DefaultTestResultCache implements \Serializable, TestResultCache
*/
private $times = [];

public function __construct($filename = null)
public function __construct($filepath = null)
{
$this->cacheFilename = $filename ?? $_ENV['PHPUNIT_RESULT_CACHE'] ?? self::DEFAULT_RESULT_CACHE_FILENAME;
if ($filepath !== null && \is_dir($filepath)) {
// cache path provided, use default cache filename in that location
$filepath = $filepath . \DIRECTORY_SEPARATOR . self::DEFAULT_RESULT_CACHE_FILENAME;
}

$this->cacheFilename = $filepath ?? $_ENV['PHPUNIT_RESULT_CACHE'] ?? self::DEFAULT_RESULT_CACHE_FILENAME;
}

/**
Expand Down
20 changes: 16 additions & 4 deletions src/TextUI/TestRunner.php
Expand Up @@ -160,12 +160,24 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}

if ($arguments['cacheResult']) {
if (isset($arguments['cacheResultFile'])) {
$cache = new DefaultTestResultCache($arguments['cacheResultFile']);
} else {
$cache = new DefaultTestResultCache;
if (!isset($arguments['cacheResultFile'])) {
if (isset($arguments['configuration']) && $arguments['configuration'] instanceof Configuration) {
$cacheLocation = $arguments['configuration']->getFilename();
} else {
$cacheLocation = $_SERVER['PHP_SELF'];
}

$arguments['cacheResultFile'] = null;

$cacheResultFile = \realpath($cacheLocation);

if ($cacheResultFile !== false) {
$arguments['cacheResultFile'] = \dirname($cacheResultFile);
}
}

$cache = new DefaultTestResultCache($arguments['cacheResultFile']);

$this->addExtension(new ResultCacheExtension($cache));
}

Expand Down

0 comments on commit 795abc1

Please sign in to comment.