9bfb6ae334
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).
42 lines
985 B
PHP
42 lines
985 B
PHP
<?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;
|
|
}
|
|
}
|