Skip to content

Commit b9aa3b1

Browse files
Merge branch '11.5'
2 parents 3c1f893 + e15692c commit b9aa3b1

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Runner/ResultCache/DefaultResultCache.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public function time(string $id): float
8080
return $this->times[$id] ?? 0.0;
8181
}
8282

83+
public function mergeWith(self $other): void
84+
{
85+
foreach ($other->defects as $id => $defect) {
86+
$this->defects[$id] = $defect;
87+
}
88+
89+
foreach ($other->times as $id => $time) {
90+
$this->times[$id] = $time;
91+
}
92+
}
93+
8394
public function load(): void
8495
{
8596
if (!is_file($this->cacheFilename)) {

tests/unit/Runner/ResultCache/DefaultResultCacheTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,32 @@ public function testCanPersistCacheToFile(): void
6868

6969
unlink($cacheFile);
7070
}
71+
72+
public function testCanBeMerged(): void
73+
{
74+
$cacheSourceOne = new DefaultResultCache;
75+
$cacheSourceOne->setStatus('status.a', TestStatus::skipped());
76+
$cacheSourceOne->setStatus('status.b', TestStatus::incomplete());
77+
$cacheSourceOne->setTime('time.a', 1);
78+
$cacheSourceOne->setTime('time.b', 2);
79+
$cacheSourceTwo = new DefaultResultCache;
80+
$cacheSourceTwo->setStatus('status.c', TestStatus::failure());
81+
$cacheSourceTwo->setTime('time.c', 4);
82+
83+
$sum = new DefaultResultCache;
84+
$sum->mergeWith($cacheSourceOne);
85+
86+
$this->assertSame(TestStatus::skipped()->asString(), $sum->status('status.a')->asString());
87+
$this->assertSame(TestStatus::incomplete()->asString(), $sum->status('status.b')->asString());
88+
$this->assertNotSame(TestStatus::failure()->asString(), $sum->status('status.c')->asString());
89+
90+
$this->assertSame(1.0, $sum->time('time.a'));
91+
$this->assertSame(2.0, $sum->time('time.b'));
92+
$this->assertNotSame(4.0, $sum->time('time.c'));
93+
94+
$sum->mergeWith($cacheSourceTwo);
95+
96+
$this->assertSame(TestStatus::failure()->asString(), $sum->status('status.c')->asString());
97+
$this->assertSame(4.0, $sum->time('time.c'));
98+
}
7199
}

0 commit comments

Comments
 (0)