M1: PHPUnit test suite for crypto, repository and resumable runs

Dev tooling via composer (phpunit, psalm, nextcloud/ocp); vendor/ is
mounted from outside the repository by a helper script. 28 unit tests
ported from the phase-0 spikes (round trips, corruption, wrong keys,
dedup, incremental runs, partial restore, tampering, object binding,
time-boxed steps, file changed between steps).
This commit is contained in:
2026-10-02 00:32:56 +02:00
parent 08e4ed52d8
commit bf3437ae10
11 changed files with 5438 additions and 3 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace OCA\NgBackup\Tests\Unit;
trait TempDirTrait {
/** @var list<string> */
private array $tempDirs = [];
protected function tempDir(): string {
$dir = sys_get_temp_dir() . '/ngb-test-' . bin2hex(random_bytes(6));
mkdir($dir, 0700, true);
$this->tempDirs[] = $dir;
return $dir;
}
protected function tearDown(): void {
foreach ($this->tempDirs as $dir) {
exec('rm -rf ' . escapeshellarg($dir));
}
$this->tempDirs = [];
parent::tearDown();
}
/** @return array<string, string> relative path => sha256 */
protected static function hashTree(string $root): array {
$out = [];
if (!is_dir($root)) {
return $out;
}
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root, \FilesystemIterator::SKIP_DOTS));
foreach ($it as $f) {
if ($f->isFile()) {
$out[substr($f->getPathname(), strlen($root) + 1)] = hash_file('sha256', $f->getPathname());
}
}
ksort($out);
return $out;
}
}