From c00bff4d25a9055a634309e9e62270ae96c59eea Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:11:45 +0000 Subject: [PATCH 1/4] fix: restore PHP config for occ subprocesses Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- features/bootstrap/console.php | 7 ++++++- features/test.feature | 7 +++++++ src/NextcloudApiContext.php | 31 ++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/features/bootstrap/console.php b/features/bootstrap/console.php index 60e588d..9b09bb2 100644 --- a/features/bootstrap/console.php +++ b/features/bootstrap/console.php @@ -6,7 +6,12 @@ * the occ commands execution. */ -if (in_array('invalid-command', $argv)) { +if (in_array('php-config', $argv, true)) { + echo 'scanned=' . (php_ini_scanned_files() !== false ? '1' : '0') . PHP_EOL; + exit; +} + +if (in_array('invalid-command', $argv, true)) { echo "Invalid command\n"; exit(1); } diff --git a/features/test.feature b/features/test.feature index ea21f48..438eb7e 100644 --- a/features/test.feature +++ b/features/test.feature @@ -339,3 +339,10 @@ Feature: Test this extension """ And sending "POST" to "/" Then the response body should match the regular expression "^%PDF" + + Scenario: Occ command keeps PHP configuration after persistent Xdebug restart + When run the command "php-config" with result code 0 + Then the output of the last command should contain the following text: + """ + scanned=1 + """ diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index e2dd98a..f6ef555 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -2,6 +2,7 @@ namespace Libresign\NextcloudBehat; +use Composer\XdebugHandler\XdebugHandler; use Behat\Behat\Context\Context; use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; @@ -598,21 +599,41 @@ public static function runCommand(string $command): array { throw new \Exception('Could not retrieve owner information for UID ' . $fileOwnerUid); } $baseCommand = 'php ' . $console . ' ' . $command; - $environmentPrefix = !empty(self::$environments) - ? http_build_query(self::$environments, '', ' ') - : ''; + $commandEnvironment = self::$environments; + $restartSettings = XdebugHandler::getRestartSettings(); + if ($restartSettings !== null) { + $commandEnvironment['PHP_INI_SCAN_DIR'] = $restartSettings['scanDir']; + $commandEnvironment['PHPRC'] = $restartSettings['phprc']; + $commandEnvironment['XDEBUG_MODE'] = 'off'; + } + $environmentPrefix = self::buildEnvironmentPrefix($commandEnvironment); if (posix_getuid() !== $owner['uid']) { - $fullCommand = 'runuser -u ' . $owner['name'] . ' -- ' + $fullCommand = 'runuser -u ' . escapeshellarg($owner['name']) . ' -- ' . ($environmentPrefix !== '' ? 'env ' . $environmentPrefix . ' ' : '') . $baseCommand; } else { - $fullCommand = ($environmentPrefix !== '' ? $environmentPrefix . ' ' : '') . $baseCommand; + $fullCommand = ($environmentPrefix !== '' ? 'env ' . $environmentPrefix . ' ' : '') . $baseCommand; } $fullCommand .= ' 2>&1'; return self::runBashCommand($fullCommand); } + /** + * @param array $environment + */ + private static function buildEnvironmentPrefix(array $environment): string { + $parts = []; + foreach ($environment as $name => $value) { + if ($value === false) { + $parts[] = '-u ' . escapeshellarg($name); + continue; + } + $parts[] = $name . '=' . escapeshellarg($value); + } + return implode(' ', $parts); + } + public static function findParentDirContainingFile(string $filename): string { $dir = getcwd(); if (is_bool($dir)) { From 376275c7629da8b2d3e9dc37aa88586911efbd4e Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:11:55 +0000 Subject: [PATCH 2/4] test: cover occ PHP config after Xdebug restart Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/behat.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 4adf4e0..b97c062 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -26,3 +26,24 @@ jobs: - name: Run behat run: vendor/bin/behat -f pretty --colors + + xdebug-persistent-occ: + runs-on: ubuntu-latest + + steps: + - name: Checkout app + uses: actions/checkout@v4 + + - name: Set up PHP with Xdebug and APCu + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + coverage: xdebug + extensions: apcu + + - name: Set up dependencies + run: composer install + + - name: Run Behat after persistent Xdebug restart + run: | + XDEBUG_HANDLER_DEBUG=2 vendor/bin/behat features/test.feature --name "Occ command keeps PHP configuration after persistent Xdebug restart" -f pretty --colors From 2def9c12a1ee1eb43c9de7daec3bf101ec30d03f Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:29:58 +0000 Subject: [PATCH 3/4] fix: order env options before assignments Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/NextcloudApiContext.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index f6ef555..c8e016c 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -623,15 +623,16 @@ public static function runCommand(string $command): array { * @param array $environment */ private static function buildEnvironmentPrefix(array $environment): string { - $parts = []; + $options = []; + $assignments = []; foreach ($environment as $name => $value) { if ($value === false) { - $parts[] = '-u ' . escapeshellarg($name); + $options[] = '-u ' . escapeshellarg($name); continue; } - $parts[] = $name . '=' . escapeshellarg($value); + $assignments[] = $name . '=' . escapeshellarg($value); } - return implode(' ', $parts); + return implode(' ', [...$options, ...$assignments]); } public static function findParentDirContainingFile(string $filename): string { From 7c7e066399cf035ed37fd576e6db7a721b21f233 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:33:33 +0000 Subject: [PATCH 4/4] style: sort xdebug handler import Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/NextcloudApiContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index c8e016c..bf68b20 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -2,7 +2,6 @@ namespace Libresign\NextcloudBehat; -use Composer\XdebugHandler\XdebugHandler; use Behat\Behat\Context\Context; use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; @@ -11,6 +10,7 @@ use Behat\Hook\BeforeSuite; use Behat\Step\Given; use Behat\Testwork\Hook\Scope\BeforeSuiteScope; +use Composer\XdebugHandler\XdebugHandler; use DOMDocument; use Exception; use GuzzleHttp\Client;