@@ -30,10 +30,13 @@ class NextcloudApiContext implements Context {
3030 protected RunServerListener $ server ;
3131 protected string $ currentUser = '' ;
3232 protected array $ fields = [];
33+ protected static array $ environments = [];
34+ protected static string $ commandOutput = '' ;
35+
3336 /**
3437 * @var string[]
3538 */
36- protected array $ createdUsers = [];
39+ protected static array $ createdUsers = [];
3740 protected ResponseInterface $ response ;
3841 /** @var CookieJar[] */
3942 protected $ cookieJars ;
@@ -63,11 +66,13 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
6366 "runuser -u %s -- %s \n\n" ,
6467 get_current_user (), $ whoami , get_current_user (), $ command ));
6568 }
69+ self ::runCommand ('config:system:set debug --value true --type boolean ' );
6670 }
6771
6872 #[BeforeScenario()]
69- public function setUp (): void {
70- $ this ->createdUsers = [];
73+ public function beforeScenario (): void {
74+ self ::$ createdUsers = [];
75+ self ::$ environments = [];
7176 }
7277
7378 #[Given('as user :user ' )]
@@ -110,7 +115,7 @@ protected function createUser(string $user): void {
110115 $ this ->sendOCSRequest ('GET ' , '/cloud/users ' . '/ ' . $ user );
111116 $ this ->assertStatusCode ($ this ->response , 200 , 'Failed to do first login ' );
112117
113- $ this -> createdUsers [] = $ user ;
118+ self :: $ createdUsers [] = $ user ;
114119
115120 $ this ->setCurrentUser ($ currentUser );
116121 }
@@ -461,6 +466,9 @@ public static function runCommand(string $command): array {
461466 throw new \Exception ('Could not retrieve owner information for UID ' . $ fileOwnerUid );
462467 }
463468 $ fullCommand = 'php ' . $ console . ' ' . $ command ;
469+ if (!empty (self ::$ environments )) {
470+ $ fullCommand = http_build_query (self ::$ environments , '' , ' ' ) . ' ' . $ fullCommand ;
471+ }
464472 if (posix_getuid () !== $ owner ['uid ' ]) {
465473 $ fullCommand = 'runuser -u ' . $ owner ['name ' ] . ' -- ' . $ fullCommand ;
466474 }
@@ -502,13 +510,24 @@ private static function runBashCommand(string $command): array {
502510 }
503511
504512 exec ($ command , $ output , $ resultCode );
513+ self ::$ commandOutput = implode ("\n" , $ output );
505514 return [
506515 'command ' => $ command ,
507516 'output ' => $ output ,
508517 'resultCode ' => $ resultCode ,
509518 ];
510519 }
511520
521+ #[Given('the output of the last command should contain the following text: ' )]
522+ public static function theOutputOfTheLastCommandContains (PyStringNode $ text ): void {
523+ Assert::assertStringContainsString ((string ) $ text , self ::$ commandOutput , 'The output of the last command does not contain: ' . $ text );
524+ }
525+
526+ #[Given('the output of the last command should be empty ' )]
527+ public static function theOutputOfTheLastCommandShouldBeEmpty (): void {
528+ Assert::assertEmpty (self ::$ commandOutput , 'The output of the last command should be empty, but got: ' . self ::$ commandOutput );
529+ }
530+
512531 #[Given('/^run the command "(?P<command>(?:[^"]| \\")*)" with result code (\d+)$/ ' )]
513532 public static function runCommandWithResultCode (string $ command , int $ resultCode = 0 ): void {
514533 $ return = self ::runCommand ($ command );
@@ -521,9 +540,15 @@ public static function runBashCommandWithResultCode(string $command, int $result
521540 Assert::assertEquals ($ resultCode , $ return ['resultCode ' ], print_r ($ return , true ));
522541 }
523542
543+ #[Given('create an environment :name with value :value to be used by occ command ' )]
544+ public static function createAnEnvironmentWithValueToBeUsedByOccCommand (string $ name , string $ value ):void {
545+ self ::$ environments [$ name ] = $ value ;
546+ }
547+
524548 #[AfterScenario()]
525549 public function tearDown (): void {
526- foreach ($ this ->createdUsers as $ user ) {
550+ self ::$ environments = [];
551+ foreach (self ::$ createdUsers as $ user ) {
527552 $ this ->deleteUser ($ user );
528553 }
529554 }
@@ -534,7 +559,7 @@ protected function deleteUser(string $user): ResponseInterface {
534559 $ this ->sendOCSRequest ('DELETE ' , '/cloud/users/ ' . $ user );
535560 $ this ->setCurrentUser ($ currentUser );
536561
537- unset($ this -> createdUsers [array_search ($ user , $ this -> createdUsers , true )]);
562+ unset(self :: $ createdUsers [array_search ($ user , self :: $ createdUsers , true )]);
538563
539564 return $ this ->response ;
540565 }
0 commit comments