From d4a2588e4f2c1d65c4141d94c1c5e4c452c3fecd Mon Sep 17 00:00:00 2001 From: Ewout Pieter den Ouden Date: Fri, 26 Apr 2019 16:25:14 +0200 Subject: [PATCH] Use path of configuration or executable to pin result cache in place --- src/TextUI/TestRunner.php | 12 ++++++++---- src/Util/TestResultCache.php | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/TextUI/TestRunner.php b/src/TextUI/TestRunner.php index 35e3a8e8cc5..761ded6969c 100644 --- a/src/TextUI/TestRunner.php +++ b/src/TextUI/TestRunner.php @@ -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); } diff --git a/src/Util/TestResultCache.php b/src/Util/TestResultCache.php index 3fdfc7d23c8..11972bd1c05 100644 --- a/src/Util/TestResultCache.php +++ b/src/Util/TestResultCache.php @@ -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