Skip to content

Commit 8bc952f

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 8bc952f

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

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+
public static function findParentDirContainingFile(string $filename): string {
60+
return __DIR__;
61+
}
62+
5463
/**
5564
* @inheritDoc
5665
*/

features/bootstrap/console.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/test.feature

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Feature: Test this extension
212212
When run the bash command "ls <appRootDir>" with result code 0
213213
Then the output of the last command should contain the following text:
214214
"""
215-
appinfo
215+
FeatureContext.php
216216
"""
217217

218218
Scenario: Test list Nextcloud directory with success
@@ -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: 3 additions & 4 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,7 +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');
473+
$console = static::findParentDirContainingFile('console.php');
475474
$console .= '/console.php';
476475
$fileOwnerUid = fileowner($console);
477476
if (!is_int($fileOwnerUid)) {
@@ -513,8 +512,8 @@ private static function runBashCommand(string $command): array {
513512
$patterns = [];
514513
$replacements = [];
515514
$fields = [
516-
'appRootDir' => self::findParentDirContainingFile('appinfo'),
517-
'nextcloudRootDir' => self::findParentDirContainingFile('console.php'),
515+
'appRootDir' => static::findParentDirContainingFile('appinfo'),
516+
'nextcloudRootDir' => static::findParentDirContainingFile('console.php'),
518517
];
519518
foreach ($fields as $key => $value) {
520519
$patterns[] = '/<' . $key . '>/';

0 commit comments

Comments
 (0)