Skip to content

Commit 503fba6

Browse files
committed
fix: change steps to consider execution outside Nextcloud environment
When whe run the test suit of this repository at GitHub Actions, is necessary to consider that we haven't Nextcloud installed and mock the console.php. Signed-off-by: Vitor Mattos <[email protected]>
1 parent 5f64839 commit 503fba6

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

features/bootstrap/FakeConsole.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/**
4+
* When whe run the test suit of this repository at GitHub Actions, is
5+
* necessary to consider that we haven't Nextcloud installed and mock
6+
* the occ commands execution.
7+
*/
8+
9+
if (in_array('invalid-command', $argv)) {
10+
echo "Invalid command\n";
11+
exit(1);
12+
}
13+
14+
if (getenv('OC_PASS') === '123456') {
15+
echo "I found the environment variable OC_PASS with value 123456\n";
16+
exit;
17+
}

features/bootstrap/FeatureContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ private function getLastRequest(): RequestInfo {
5151
return $lastRequest;
5252
}
5353

54+
/**
55+
* When whe run the test suit of this repository at GitHub Actions, is
56+
* necessary to consider that we haven't Nextcloud installed and mock
57+
* the occ commands execution.
58+
*/
59+
protected static function getConsolePath(): string {
60+
return __DIR__ . '/FakeConsole.php';
61+
}
62+
5463
/**
5564
* @inheritDoc
5665
*/

features/test.feature

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,14 @@ Feature: Test this extension
227227

228228
Scenario: Run occ command with success
229229
When run the command "status" with result code 0
230-
Then the output of the last command should contain the following text:
231-
"""
232-
version:
233-
"""
234230

235231
Scenario: Run occ command with success
236232
When run the command "invalid-command" with result code 1
237233

238234
Scenario: Create an environment with value to be used by occ command
239-
When create an environment "OC_PASS" with value "" to be used by occ command
240-
And run the command "user:add --password-from-env test" with result code 1
235+
When create an environment "OC_PASS" with value "123456" to be used by occ command
236+
And run the command "fake-command" with result code 0
241237
Then the output of the last command should contain the following text:
242238
"""
243-
--password-from-env given, but NC_PASS/OC_PASS is empty!
239+
I found the environment variable OC_PASS with value 123456
244240
"""

src/NextcloudApiContext.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
6464
"runuser -u %s -- %s\n\n",
6565
get_current_user(), $whoami, get_current_user(), $command));
6666
}
67-
self::runCommand('config:system:set debug --value true --type boolean');
6867
}
6968

7069
/**
@@ -471,8 +470,7 @@ protected function parseText(string $text): string {
471470
* @When /^run the command "(?P<command>(?:[^"]|\\")*)"$/
472471
*/
473472
public static function runCommand(string $command): array {
474-
$console = self::findParentDirContainingFile('console.php');
475-
$console .= '/console.php';
473+
$console = static::getConsolePath();
476474
$fileOwnerUid = fileowner($console);
477475
if (!is_int($fileOwnerUid)) {
478476
throw new \Exception('The console file owner of ' . $console . ' is not an integer UID.');
@@ -492,6 +490,12 @@ public static function runCommand(string $command): array {
492490
return self::runBashCommand($fullCommand);
493491
}
494492

493+
protected static function getConsolePath(): string {
494+
$console = self::findParentDirContainingFile('console.php');
495+
$console .= '/console.php';
496+
return $console;
497+
}
498+
495499
public static function findParentDirContainingFile(string $filename): string {
496500
$dir = getcwd();
497501
if (is_bool($dir)) {

0 commit comments

Comments
 (0)