Skip to content

Commit c586f71

Browse files
test: add test infrastructure for setup checks
Adds ExecMock, FileSystemMock, SetupCheckFunctions to mock system calls, and updates bootstrap.php to load them. Related issue: #6590 Type: Test Checklist: - [x] Create ExecMock class - [x] Create FileSystemMock class - [x] Create SetupCheckFunctions with file_exists and exec overrides - [x] Update bootstrap.php to include new files
1 parent 38f7d2f commit c586f71

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

tests/php/SetupCheckFunctions.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Libresign\SetupCheck;
11+
12+
if (!function_exists('OCA\Libresign\SetupCheck\file_exists')) {
13+
function file_exists(string $filename): bool
14+
{
15+
if (array_key_exists($filename, FileSystemMock::$files)) {
16+
return FileSystemMock::$files[$filename];
17+
}
18+
return \file_exists($filename);
19+
}
20+
}
21+
22+
if (!function_exists('OCA\Libresign\SetupCheck\exec')) {
23+
function exec(string $command, &$output = null, &$result_code = null): string|false
24+
{
25+
if (array_key_exists($command, ExecMock::$commands)) {
26+
$mock = ExecMock::$commands[$command];
27+
$output = $mock['output'];
28+
$result_code = $mock['result_code'];
29+
return $output ? implode("\n", $output) : '';
30+
}
31+
return \exec($command, $output, $result_code);
32+
}
33+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Libresign\SetupCheck;
11+
12+
class ExecMock {
13+
public static array $commands = [];
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\Libresign\SetupCheck;
6+
7+
class FileSystemMock {
8+
public static array $files = [];
9+
}

tests/php/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
require_once __DIR__ . '/../../../../lib/base.php';
1818
require_once __DIR__ . '/../../../../tests/autoload.php';
1919

20+
require_once __DIR__ . '/Unit/SetupCheck/FileSystemMock.php';
21+
require_once __DIR__ . '/Unit/SetupCheck/ExecMock.php';
22+
23+
require_once __DIR__ . '/SetupCheckFunctions.php';
24+
2025
\OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/php/lib/', true);
2126
\OC::$composerAutoloader->addPsr4('Tests\\', OC::$SERVERROOT . '/tests/php/', true);
2227
\OC::$composerAutoloader->addPsr4('OCA\\Libresign\\Tests\\', __DIR__, true);

0 commit comments

Comments
 (0)