Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion features/bootstrap/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions features/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
32 changes: 27 additions & 5 deletions src/NextcloudApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,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;
Expand Down Expand Up @@ -598,21 +599,42 @@ 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<string, string|false> $environment
*/
private static function buildEnvironmentPrefix(array $environment): string {
$options = [];
$assignments = [];
foreach ($environment as $name => $value) {
if ($value === false) {
$options[] = '-u ' . escapeshellarg($name);
continue;
}
$assignments[] = $name . '=' . escapeshellarg($value);
}
return implode(' ', [...$options, ...$assignments]);
}

public static function findParentDirContainingFile(string $filename): string {
$dir = getcwd();
if (is_bool($dir)) {
Expand Down
Loading