Skip to content

Commit

Permalink
Merge branch '10.5' into 11.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 11, 2024
2 parents b3dddef + c8c6e60 commit e15692c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-11.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi

## [11.5.1] - 2024-MM-DD

### Added

* [#6081](/~https://github.com/sebastianbergmann/phpunit/pull/6081): `DefaultResultCache::mergeWith()` for merging result cache instances

### Fixed

* [#6066](/~https://github.com/sebastianbergmann/phpunit/pull/6066): TeamCity logger does not handle error/skipped events in before-class methods correctly
Expand Down
11 changes: 11 additions & 0 deletions src/Runner/ResultCache/DefaultResultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ public function time(string $id): float
return $this->times[$id] ?? 0.0;
}

public function mergeWith(self $other): void
{
foreach ($other->defects as $id => $defect) {
$this->defects[$id] = $defect;
}

foreach ($other->times as $id => $time) {
$this->times[$id] = $time;
}
}

public function load(): void
{
if (!is_file($this->cacheFilename)) {
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/Runner/ResultCache/DefaultResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,32 @@ public function testCanPersistCacheToFile(): void

unlink($cacheFile);
}

public function testCanBeMerged(): void
{
$cacheSourceOne = new DefaultResultCache;
$cacheSourceOne->setStatus('status.a', TestStatus::skipped());
$cacheSourceOne->setStatus('status.b', TestStatus::incomplete());
$cacheSourceOne->setTime('time.a', 1);
$cacheSourceOne->setTime('time.b', 2);
$cacheSourceTwo = new DefaultResultCache;
$cacheSourceTwo->setStatus('status.c', TestStatus::failure());
$cacheSourceTwo->setTime('time.c', 4);

$sum = new DefaultResultCache;
$sum->mergeWith($cacheSourceOne);

$this->assertSame(TestStatus::skipped()->asString(), $sum->status('status.a')->asString());
$this->assertSame(TestStatus::incomplete()->asString(), $sum->status('status.b')->asString());
$this->assertNotSame(TestStatus::failure()->asString(), $sum->status('status.c')->asString());

$this->assertSame(1.0, $sum->time('time.a'));
$this->assertSame(2.0, $sum->time('time.b'));
$this->assertNotSame(4.0, $sum->time('time.c'));

$sum->mergeWith($cacheSourceTwo);

$this->assertSame(TestStatus::failure()->asString(), $sum->status('status.c')->asString());
$this->assertSame(4.0, $sum->time('time.c'));
}
}

0 comments on commit e15692c

Please sign in to comment.