From e5e5a3cb2a15f7d3e261492ae3cde18c86e41f4e Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 27 Apr 2019 14:44:04 +0200 Subject: [PATCH] Streamline types in Runner/DefaultTestResultCache.php --- src/Runner/DefaultTestResultCache.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Runner/DefaultTestResultCache.php b/src/Runner/DefaultTestResultCache.php index ca5f521221c..d4035cac85b 100644 --- a/src/Runner/DefaultTestResultCache.php +++ b/src/Runner/DefaultTestResultCache.php @@ -24,7 +24,7 @@ final class DefaultTestResultCache implements \Serializable, TestResultCache /** * Provide extra protection against incomplete or corrupt caches * - * @var array + * @var int[] */ private const ALLOWED_CACHE_TEST_STATUSES = [ BaseTestRunner::STATUS_SKIPPED, @@ -50,7 +50,7 @@ final class DefaultTestResultCache implements \Serializable, TestResultCache * $this->defects[$testName] = BaseTestRunner::TEST_SKIPPED; * * - * @var array array + * @var array */ private $defects = []; @@ -66,7 +66,7 @@ final class DefaultTestResultCache implements \Serializable, TestResultCache */ private $times = []; - public function __construct($filepath = null) + public function __construct(?string $filepath = null) { if ($filepath !== null && \is_dir($filepath)) { // cache path provided, use default cache filename in that location @@ -153,7 +153,7 @@ public function load(): void } if ($cache instanceof self) { - /* @var \PHPUnit\Runner\DefaultTestResultCache */ + /* @var DefaultTestResultCache $cache */ $cache->copyStateToCache($this); } } @@ -183,18 +183,26 @@ public function serialize(): string ]); } + /** + * @param string $serialized + */ public function unserialize($serialized): void { $data = \unserialize($serialized); if (isset($data['times'])) { foreach ($data['times'] as $testName => $testTime) { - $this->times[$testName] = (float) $testTime; + \assert(\is_string($testName)); + \assert(\is_float($testTime)); + $this->times[$testName] = $testTime; } } if (isset($data['defects'])) { foreach ($data['defects'] as $testName => $testResult) { + \assert(\is_string($testName)); + \assert(\is_int($testResult)); + if (\in_array($testResult, self::ALLOWED_CACHE_TEST_STATUSES, true)) { $this->defects[$testName] = $testResult; }