Skip to content
Permalink
Browse files

Streamline types in Runner/DefaultTestResultCache.php

  • Loading branch information...
oliverklee authored and sebastianbergmann committed Apr 27, 2019
1 parent 53b8145 commit e5e5a3cb2a15f7d3e261492ae3cde18c86e41f4e
Showing with 13 additions and 5 deletions.
  1. +13 −5 src/Runner/DefaultTestResultCache.php
@@ -24,7 +24,7 @@ final class DefaultTestResultCache implements \Serializable, TestResultCache
/**
* Provide extra protection against incomplete or corrupt caches
*
* @var array<string, string>
* @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;
* </code>
*
* @var array array<string, int>
* @var array<string, int>
*/
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;
}

0 comments on commit e5e5a3c

Please sign in to comment.
You can’t perform that action at this time.