@@ -26,10 +26,13 @@ class NextcloudApiContext implements Context {
2626 protected RunServerListener $ server ;
2727 protected string $ currentUser = '' ;
2828 protected array $ fields = [];
29+ protected static array $ environments = [];
30+ protected static string $ commandOutput = '' ;
31+
2932 /**
3033 * @var string[]
3134 */
32- protected array $ createdUsers = [];
35+ protected static array $ createdUsers = [];
3336 protected ResponseInterface $ response ;
3437 /** @var CookieJar[] */
3538 protected $ cookieJars ;
@@ -61,13 +64,15 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
6164 "runuser -u %s -- %s \n\n" ,
6265 get_current_user (), $ whoami , get_current_user (), $ command ));
6366 }
67+ self ::runCommand ('config:system:set debug --value true --type boolean ' );
6468 }
6569
6670 /**
6771 * @BeforeScenario
6872 */
69- public function setUp (): void {
70- $ this ->createdUsers = [];
73+ public function beforeScenario (): void {
74+ self ::$ createdUsers = [];
75+ self ::$ environments = [];
7176 }
7277
7378 /**
@@ -116,7 +121,7 @@ protected function createUser(string $user): void {
116121 $ this ->sendOCSRequest ('GET ' , '/cloud/users ' . '/ ' . $ user );
117122 $ this ->assertStatusCode ($ this ->response , 200 , 'Failed to do first login ' );
118123
119- $ this -> createdUsers [] = $ user ;
124+ self :: $ createdUsers [] = $ user ;
120125
121126 $ this ->setCurrentUser ($ currentUser );
122127 }
@@ -477,6 +482,9 @@ public static function runCommand(string $command): array {
477482 throw new \Exception ('Could not retrieve owner information for UID ' . $ fileOwnerUid );
478483 }
479484 $ fullCommand = 'php ' . $ console . ' ' . $ command ;
485+ if (!empty (self ::$ environments )) {
486+ $ fullCommand = http_build_query (self ::$ environments , '' , ' ' ) . ' ' . $ fullCommand ;
487+ }
480488 if (posix_getuid () !== $ owner ['uid ' ]) {
481489 $ fullCommand = 'runuser -u ' . $ owner ['name ' ] . ' -- ' . $ fullCommand ;
482490 }
@@ -518,13 +526,28 @@ private static function runBashCommand(string $command): array {
518526 }
519527
520528 exec ($ command , $ output , $ resultCode );
529+ self ::$ commandOutput = implode ("\n" , $ output );
521530 return [
522531 'command ' => $ command ,
523532 'output ' => $ output ,
524533 'resultCode ' => $ resultCode ,
525534 ];
526535 }
527536
537+ /**
538+ * @When the output of the last command should contain the following text:
539+ */
540+ public static function theOutputOfTheLastCommandContains (PyStringNode $ text ): void {
541+ Assert::assertStringContainsString ((string ) $ text , self ::$ commandOutput , 'The output of the last command does not contain: ' . $ text );
542+ }
543+
544+ /**
545+ * @When the output of the last command should be empty
546+ */
547+ public static function theOutputOfTheLastCommandShouldBeEmpty (): void {
548+ Assert::assertEmpty (self ::$ commandOutput , 'The output of the last command should be empty, but got: ' . self ::$ commandOutput );
549+ }
550+
528551 /**
529552 * @When /^run the command "(?P<command>(?:[^"]|\\")*)" with result code (\d+)$/
530553 */
@@ -541,11 +564,19 @@ public static function runBashCommandWithResultCode(string $command, int $result
541564 Assert::assertEquals ($ resultCode , $ return ['resultCode ' ], print_r ($ return , true ));
542565 }
543566
567+ /**
568+ * @When create an environment :name with value :value to be used by occ command
569+ */
570+ public static function createAnEnvironmentWithValueToBeUsedByOccCommand (string $ name , string $ value ):void {
571+ self ::$ environments [$ name ] = $ value ;
572+ }
573+
544574 /**
545575 * @AfterScenario
546576 */
547577 public function tearDown (): void {
548- foreach ($ this ->createdUsers as $ user ) {
578+ self ::$ environments = [];
579+ foreach (self ::$ createdUsers as $ user ) {
549580 $ this ->deleteUser ($ user );
550581 }
551582 }
@@ -556,7 +587,7 @@ protected function deleteUser(string $user): ResponseInterface {
556587 $ this ->sendOCSRequest ('DELETE ' , '/cloud/users/ ' . $ user );
557588 $ this ->setCurrentUser ($ currentUser );
558589
559- unset($ this -> createdUsers [array_search ($ user , $ this -> createdUsers , true )]);
590+ unset(self :: $ createdUsers [array_search ($ user , self :: $ createdUsers , true )]);
560591
561592 return $ this ->response ;
562593 }
0 commit comments