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:
co-authored by
Claude Opus 5.5
parent
60c31f9697
commit
fc8ffeba9e
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,4 +43,32 @@ final class PresetAreaTest extends TestCase
|
||||
self::assertFalse($area->verify($expected, $missing));
|
||||
self::assertFalse($area->verify($expected, $otherDefault));
|
||||
}
|
||||
|
||||
/** Final review I-3a: a snapshot is written back with full-replace semantics. */
|
||||
public function testRestoreReplacesTheWholeInventory(): void
|
||||
{
|
||||
$writer = Mockery::mock(DesignSystemWriter::class);
|
||||
$stored = PresetBookTest::stored();
|
||||
$writer->expects('savePresets')->with(PresetBook::fromDivi($stored)->toRest(), true)->andReturn($stored);
|
||||
|
||||
self::assertSame(PresetBook::fromDivi($stored)->data(), (new PresetArea($writer))->restore($stored));
|
||||
}
|
||||
|
||||
/** Final review I-3b: values Divi changed while saving, by preset name; structure is verify()'s job. */
|
||||
public function testDifferencesNameThePresetsDiviSanitized(): void
|
||||
{
|
||||
$area = new PresetArea(Mockery::mock(DesignSystemWriter::class));
|
||||
$expected = PresetBookTest::stored();
|
||||
$sanitized = $expected;
|
||||
$sanitized['module']['divi/button']['items']['aaaaaaaaaa']['attrs'] = ['button' => ['x' => 'bereinigt']];
|
||||
$missing = $expected;
|
||||
unset($missing['module']['divi/button']['items']['bbbbbbbbbb']);
|
||||
|
||||
self::assertSame([], $area->differences($expected, $expected));
|
||||
self::assertSame([], $area->differences($expected, $missing));
|
||||
self::assertSame(
|
||||
['Divi hat die Einstellungen von Preset „CTA primär“ beim Speichern bereinigt.'],
|
||||
$area->differences($expected, $sanitized)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user