Skip to content

Commit 2fc5a50

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 <1079143+vitormattos@users.noreply.github.com>
1 parent 5980376 commit 2fc5a50

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

features/bootstrap/FeatureContext.php

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

55+
/**
56+
* When whe run the test suit of this repository at GitHub Actions, is
57+
* necessary to consider that we haven't Nextcloud installed and mock
58+
* the real path of files.
59+
*/
60+
public static function findParentDirContainingFile(string $filename): string {
61+
return __DIR__;
62+
}
63+
5564
/**
5665
* @inheritDoc
5766
*/

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
@@ -232,7 +232,7 @@ Feature: Test this extension
232232
When run the bash command "ls <appRootDir>" with result code 0
233233
Then the output of the last command should contain the following text:
234234
"""
235-
appinfo
235+
FeatureContext.php
236236
"""
237237

238238
Scenario: Test list Nextcloud directory with success
@@ -247,18 +247,14 @@ Feature: Test this extension
247247

248248
Scenario: Run occ command with success
249249
When run the command "status" with result code 0
250-
Then the output of the last command should contain the following text:
251-
"""
252-
version:
253-
"""
254250

255251
Scenario: Run occ command with success
256252
When run the command "invalid-command" with result code 1
257253

258254
Scenario: Create an environment with value to be used by occ command
259-
When create an environment "OC_PASS" with value "" to be used by occ command
260-
And run the command "user:add --password-from-env test" with result code 1
255+
When create an environment "OC_PASS" with value "123456" to be used by occ command
256+
And run the command "fake-command" with result code 0
261257
Then the output of the last command should contain the following text:
262258
"""
263-
--password-from-env given, but NC_PASS/OC_PASS is empty!
259+
I found the environment variable OC_PASS with value 123456
264260
"""

src/NextcloudApiContext.php

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

7271
#[BeforeScenario()]
@@ -455,7 +454,7 @@ protected function parseText(string $text): string {
455454

456455
#[Given('/^run the command "(?P<command>(?:[^"]|\\")*)"$/')]
457456
public static function runCommand(string $command): array {
458-
$console = self::findParentDirContainingFile('console.php');
457+
$console = static::findParentDirContainingFile('console.php');
459458
$console .= '/console.php';
460459
$fileOwnerUid = fileowner($console);
461460
if (!is_int($fileOwnerUid)) {
@@ -497,8 +496,8 @@ private static function runBashCommand(string $command): array {
497496
$patterns = [];
498497
$replacements = [];
499498
$fields = [
500-
'appRootDir' => self::findParentDirContainingFile('appinfo'),
501-
'nextcloudRootDir' => self::findParentDirContainingFile('console.php'),
499+
'appRootDir' => static::findParentDirContainingFile('appinfo'),
500+
'nextcloudRootDir' => static::findParentDirContainingFile('console.php'),
502501
];
503502
foreach ($fields as $key => $value) {
504503
$patterns[] = '/<' . $key . '>/';

0 commit comments

Comments
 (0)