first commit.

This commit is contained in:
kj
2026-10-05 15:08:39 -03:00
commit b7799f9fff
93 changed files with 8966 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
<?php
use Toolbox\Drift;
use Toolbox\FileSync;
Harness::suite('group3-drift');
Harness::it('sin drift escribe/reescribe', function () {
$dir = tmpdir();
$file = $dir . '/a.php';
$sync = new FileSync();
eq(FileSync::WRITTEN, $sync->write($file, 'uno', null));
eq('uno', file_get_contents($file));
$hash = Drift::hash($file);
eq(FileSync::OVERWRITTEN, $sync->write($file, 'dos', $hash));
rrmdir($dir);
});
Harness::it('drift sin bandera aborta', function () {
$dir = tmpdir();
$file = $dir . '/a.php';
write_file($file, 'original');
$hash = Drift::hash($file);
write_file($file, 'editado');
$sync = new FileSync();
eq(FileSync::ABORTED, $sync->write($file, 'nuevo', $hash));
eq('editado', file_get_contents($file));
rrmdir($dir);
});
Harness::it('--force sobreescribe el drift', function () {
$dir = tmpdir();
$file = $dir . '/a.php';
write_file($file, 'original');
$hash = Drift::hash($file);
write_file($file, 'editado');
$sync = new FileSync();
eq(FileSync::OVERWRITTEN, $sync->write($file, 'nuevo', $hash, ['force' => true]));
eq('nuevo', file_get_contents($file));
rrmdir($dir);
});
Harness::it('--backup respalda y escribe', function () {
$dir = tmpdir();
$file = $dir . '/a.php';
write_file($file, 'original');
$hash = Drift::hash($file);
write_file($file, 'editado');
$sync = new FileSync();
eq(FileSync::BACKED_UP, $sync->write($file, 'nuevo', $hash, ['backup' => true]));
eq('nuevo', file_get_contents($file));
eq('editado', file_get_contents($file . '.bak'));
rrmdir($dir);
});
Harness::it('--backup respalda en la primera escritura sin hash previo', function () {
$dir = tmpdir();
$file = $dir . '/a.php';
write_file($file, 'heredado');
$sync = new FileSync();
eq(FileSync::BACKED_UP, $sync->write($file, 'canonico', null, ['backup' => true]));
eq('canonico', file_get_contents($file));
eq('heredado', file_get_contents($file . '.bak'), 'conserva la copia heredada');
rrmdir($dir);
});
Harness::it('--keep-local conserva y no escribe', function () {
$dir = tmpdir();
$file = $dir . '/a.php';
write_file($file, 'original');
$hash = Drift::hash($file);
write_file($file, 'editado');
$sync = new FileSync();
eq(FileSync::SKIPPED, $sync->write($file, 'nuevo', $hash, ['keepLocal' => true]));
eq('editado', file_get_contents($file));
rrmdir($dir);
});