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); });