-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
DefaultTestResultCacheTest.php
65 lines (55 loc) · 2.24 KB
/
DefaultTestResultCacheTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Runner;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestStatus\TestStatus;
use ReflectionClass;
/**
* @covers \PHPUnit\Runner\DefaultTestResultCache
* @small
*/
final class DefaultTestResultCacheTest extends TestCase
{
private DefaultTestResultCache $subject;
protected function setUp(): void
{
$this->subject = new DefaultTestResultCache;
}
public function testGetTimeForNonExistentTestNameReturnsFloatZero(): void
{
$this->assertSame(0.0, $this->subject->time('doesNotExist'));
}
public function testOldResultCacheFormatDoesNotTriggerError(): void
{
// PHPUnit before version 10 used integer constants instead of TestStatus.
// Note: this is a quick and cheap test for this uncommon edge case, without having
// to set up a full end-to-end test with an old cache file
$cache = new DefaultTestResultCache;
$reflectedCache = new ReflectionClass($cache);
// Set a test status in the old integer and new value-object format
$defects = $reflectedCache->getProperty('defects');
$defects->setAccessible(true);
$defects->setValue($cache, [
'newStatus' => TestStatus::skipped(),
'legacyStatus' => 1,
]);
// Simulate a save-load cycle
$loadedCache = unserialize(serialize($cache));
$this->assertTrue($loadedCache instanceof DefaultTestResultCache);
$this->assertEquals(TestStatus::skipped(), $loadedCache->status('newStatus'));
$this->assertEquals(TestStatus::unknown(), $loadedCache->status('legacyStatus'));
// Test the state duplication internals
$copiedCache = new DefaultTestResultCache;
/* @var DefaultTestResultCache $loadedCache */
$cache->copyStateToCache($copiedCache);
$this->assertEquals(TestStatus::skipped(), $copiedCache->status('newStatus'));
$this->assertEquals(TestStatus::unknown(), $copiedCache->status('legacyStatus'));
}
}