diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index 11d770cdbe..3f860827b0 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -2,6 +2,42 @@ declare(strict_types=1); +namespace Test; + +/** + * Overwrite opendir in the Test namespace. + */ + +function testCaseWillIgnore(string $node): bool { + $libresignPath = current(glob(\OC::$SERVERROOT . '/data/appdata_*/libresign')); + $knownEntries = [ + $libresignPath . '/aarch', + $libresignPath . '/arm64', + $libresignPath . '/cfssl_config', + $libresignPath . '/x86_64', + ]; + foreach ($knownEntries as $ignored) { + if (str_starts_with($node, $ignored)) { + return true; + } + } + return false; +} + +function rmdir($dir) { + if (testCaseWillIgnore($dir)) { + return false; + } + return \rmdir($dir); +} + +function unlink($file) { + if (testCaseWillIgnore($file)) { + return false; + } + return \unlink($file); +} + namespace OCA\Libresign\Tests\Unit; use donatj\MockWebServer\MockWebServer; @@ -200,11 +236,14 @@ private function getBinariesFromCache(): void { } private function getFullLiresignAppFolder(): string { - $libresignPath = glob('../../data/appdata_*/libresign'); - if (empty($libresignPath)) { - return ''; + $path = '../../data/appdata_' . \OC_Util::getInstanceId() . '/libresign'; + if (!is_dir($path)) { + mkdir($path, 0777, true); + $user = fileowner(__FILE__); + chown($path, $user); + chgrp($path, $user); } - return realpath(current($libresignPath)); + return realpath($path); } private function backupBinaries(): void {