fix: DesignArea mit restore() fürs Zurückschreiben und differences() für bereinigte Werte

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-16 18:04:34 +02:00
co-authored by Claude Opus 5.5
parent 60c31f9697
commit fc8ffeba9e
5 changed files with 130 additions and 12 deletions
@@ -22,14 +22,27 @@ use RuntimeException;
final class DesignChangeTest extends TestCase
{
/** A DesignArea over an array; $failWrite/$failRestore make write()/the rollback throw. */
private static function area(array &$stored, int $failWrites = 0, bool $verify = true): DesignArea
{
return new class ($stored, $failWrites, $verify) implements DesignArea {
/**
* A DesignArea over an array; the first $failWrites calls of write()/restore() throw, $differences are the
* value warnings of differences().
*/
private static function area(
array &$stored,
int $failWrites = 0,
bool $verify = true,
array $differences = []
): DesignArea {
return new class ($stored, $failWrites, $verify, $differences) implements DesignArea {
public array $writes = [];
public function __construct(private array &$stored, private int $failWrites, private bool $verify)
{
public array $restores = [];
public function __construct(
private array &$stored,
private int $failWrites,
private bool $verify,
private array $differences
) {
}
public function name(): string
@@ -64,10 +77,27 @@ final class DesignChangeTest extends TestCase
return $raw;
}
public function restore(array $raw): array
{
$this->restores[] = $raw;
if ($this->failWrites > 0) {
--$this->failWrites;
throw new RuntimeException('divi refused the restore');
}
$this->stored = $raw;
return $raw;
}
public function verify(array $expected, array $actual): bool
{
return $this->verify;
}
public function differences(array $expected, array $actual): array
{
return $this->differences;
}
};
}
@@ -178,6 +208,26 @@ final class DesignChangeTest extends TestCase
self::assertSame('presets-1', $log->records[0]['snapshot_id']);
}
/** Final review I-3b: values Divi changed while saving are reported as warnings. */
public function testValuesDiviChangedWhileSavingAreWarnings(): void
{
$stored = ['v' => 1];
$area = self::area($stored, 0, true, ['Divi hat die Einstellungen von Preset „CTA“ beim Speichern bereinigt.']);
$snapshots = Mockery::mock(SnapshotStore::class);
$snapshots->expects('save')->andReturn('presets-1');
$snapshots->expects('attachLog');
$result = (new DesignChange($snapshots, new FakeChangeLog(9)))->run(
'lit/divi-presets-set',
$area,
['confirm' => true, 'design_rev' => $area->rev($stored)],
self::plan(['v' => 2])
);
self::assertTrue($result['ok']);
self::assertContains('Divi hat die Einstellungen von Preset „CTA“ beim Speichern bereinigt.', $result['warnings']);
}
public function testLockedDiviWritesNoSnapshot(): void
{
ReleaseGate::useResolver(static fn (): ReleaseStatus => new ReleaseStatus(ReleaseState::Untested, '5.16.0'));
@@ -234,7 +284,8 @@ final class DesignChangeTest extends TestCase
self::assertSame('presets-1', $e->details['snapshot_id']);
}
self::assertSame([[['v' => 2], false], [['v' => 1], true]], $area->writes);
self::assertSame([[['v' => 2], false]], $area->writes);
self::assertSame([['v' => 1]], $area->restores, 'the rollback writes the snapshot back with restore()');
self::assertSame(['v' => 1], $stored);
}