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 26, 2019
1 parent ea74787 commit d4a2588
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,16 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}

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

$cache = new TestResultCache($arguments['cacheResultFile']);
$this->extensions[] = new ResultCacheExtension($cache);
}

Expand Down
9 changes: 7 additions & 2 deletions src/Util/TestResultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ class TestResultCache implements \Serializable, TestResultCacheInterface
*/
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;
}

public function persist(): void
Expand Down

0 comments on commit d4a2588

Please sign in to comment.