55use Behat \Behat \Context \Context ;
66use Behat \Gherkin \Node \PyStringNode ;
77use Behat \Gherkin \Node \TableNode ;
8+ use Behat \Hook \AfterScenario ;
9+ use Behat \Hook \BeforeScenario ;
10+ use Behat \Hook \BeforeSuite ;
11+ use Behat \Step \Given ;
812use Behat \Testwork \Hook \Scope \BeforeSuiteScope ;
913use DOMDocument ;
1014use Exception ;
@@ -53,9 +57,7 @@ public function __construct(?array $parameters = []) {
5357 }
5458 }
5559
56- /**
57- * @BeforeSuite
58- */
60+ #[BeforeSuite()]
5961 public static function beforeSuite (BeforeSuiteScope $ scope ):void {
6062 $ whoami = (string ) exec ('whoami ' );
6163 if (get_current_user () !== $ whoami ) {
@@ -68,24 +70,18 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
6870 }
6971 }
7072
71- /**
72- * @BeforeScenario
73- */
73+ #[BeforeScenario()]
7474 public static function beforeScenario (): void {
7575 self ::$ createdUsers = [];
7676 self ::$ environments = [];
7777 }
7878
79- /**
80- * @Given as user :user
81- */
79+ #[Given('as user :user ' )]
8280 public function setCurrentUser (string $ user ): void {
8381 $ this ->currentUser = $ user ;
8482 }
8583
86- /**
87- * @Given user :user exists
88- */
84+ #[Given('user :user exists ' )]
8985 public function assureUserExists (string $ user ): void {
9086 $ response = $ this ->userExists ($ user );
9187 if ($ response ->getStatusCode () !== 200 ) {
@@ -98,9 +94,7 @@ public function assureUserExists(string $user): void {
9894 }
9995 }
10096
101- /**
102- * @Given guest :guest exists
103- */
97+ #[Given('guest :guest exists ' )]
10498 public function assureGuestExists (string $ guest ): void {
10599 $ response = $ this ->userExists ($ guest );
106100 if ($ response ->getStatusCode () !== 200 ) {
@@ -140,9 +134,7 @@ protected function createUser(string $user): void {
140134 $ this ->setCurrentUser ($ currentUser );
141135 }
142136
143- /**
144- * @Given /^set the display name of user "([^"]*)" to "([^"]*)"$/
145- */
137+ #[Given('/^set the display name of user "([^"]*)" to "([^"]*)"$/ ' )]
146138 public function setUserDisplayName (string $ user , ?string $ displayName = null ): void {
147139 $ currentUser = $ this ->currentUser ;
148140 $ this ->setCurrentUser ('admin ' );
@@ -154,9 +146,7 @@ public function setUserDisplayName(string $user, ?string $displayName = null): v
154146 $ this ->setCurrentUser ($ currentUser );
155147 }
156148
157- /**
158- * @Given /^set the email of user "([^"]*)" to "([^"]*)"$/
159- */
149+ #[Given('/^set the email of user "([^"]*)" to "([^"]*)"$/ ' )]
160150 public function setUserEmail (string $ user , string $ email ): void {
161151 $ currentUser = $ this ->currentUser ;
162152 $ this ->setCurrentUser ('admin ' );
@@ -171,8 +161,8 @@ public function setUserEmail(string $user, string $email): void {
171161 * @param string $verb
172162 * @param string $url
173163 * @param TableNode|array|null $body
174- * @Given sending :verb to ocs :url
175164 */
165+ #[Given('sending :verb to ocs :url ' )]
176166 public function sendOCSRequest (string $ verb , string $ url , $ body = null , array $ headers = [], array $ options = []): void {
177167 $ url = '/ocs/v2.php ' . $ url ;
178168 $ headers ['OCS-ApiRequest ' ] = 'true ' ;
@@ -184,8 +174,8 @@ public function sendOCSRequest(string $verb, string $url, $body = null, array $h
184174 * @param string $url
185175 * @param TableNode|PyStringNode|array|null $body
186176 * @param array $headers
187- * @Given sending :verb to :url
188177 */
178+ #[Given('sending :verb to :url ' )]
189179 public function sendRequest (string $ verb , string $ url , $ body = null , array $ headers = [], array $ options = []): void {
190180 if (!str_starts_with ($ url , '/ ' )) {
191181 $ url = '/ ' . $ url ;
@@ -273,9 +263,7 @@ private function normalizePayloadForRequest(string $verb, array $options): array
273263 return $ options ;
274264 }
275265
276- /**
277- * @Given /^set the custom http header "([^"]*)" with "([^"]*)" as value to next request$/
278- */
266+ #[Given('/^set the custom http header "([^"]*)" with "([^"]*)" as value to next request$/ ' )]
279267 public function setTheCustomHttpHeaderAsValueToNextRequest (string $ header , string $ value ):void {
280268 if (empty ($ value )) {
281269 unset($ this ->customHeaders [$ header ]);
@@ -325,9 +313,7 @@ protected function assertStatusCode(ResponseInterface $response, int $statusCode
325313 /**
326314 * @throws \InvalidArgumentException
327315 */
328- /**
329- * @Given the response should have a status code :code
330- */
316+ #[Given('the response should have a status code :code ' )]
331317 public function theResponseShouldHaveStatusCode (string $ code ): void {
332318 $ currentCode = $ this ->response ->getStatusCode ();
333319 Assert::assertEquals ($ code , $ currentCode , $ this ->response ->getBody ()->getContents ());
@@ -336,9 +322,7 @@ public function theResponseShouldHaveStatusCode(string $code): void {
336322 /**
337323 * @throws \InvalidArgumentException
338324 */
339- /**
340- * @Given the response should be a JSON array with the following mandatory values
341- */
325+ #[Given('the response should be a JSON array with the following mandatory values ' )]
342326 public function theResponseShouldBeAJsonArrayWithTheFollowingMandatoryValues (TableNode $ table ): void {
343327 $ this ->response ->getBody ()->seek (0 );
344328 $ expectedValues = $ table ->getColumnsHash ();
@@ -412,9 +396,7 @@ private function validateAsJsonQuery(string $expected, string $actual): void {
412396 Assert::assertTrue ($ result , 'The jq " ' . $ expected . '" do not match with: ' . $ actual );
413397 }
414398
415- /**
416- * @Given fetch field :path from previous JSON response
417- */
399+ #[Given('fetch field :path from previous JSON response ' )]
418400 public function fetchFieldFromPreviousJsonResponse (string $ path ): void {
419401 $ this ->response ->getBody ()->seek (0 );
420402 $ body = $ this ->response ->getBody ()->getContents ();
@@ -445,9 +427,7 @@ public function fetchFieldFromPreviousJsonResponse(string $path): void {
445427 $ this ->fields [$ path ] = $ value ;
446428 }
447429
448- /**
449- * @Given the response should contain the initial state :name with the following values:
450- */
430+ #[Given('the response should contain the initial state :name with the following values: ' )]
451431 public function theResponseShouldContainTheInitialStateWithTheFollowingValues (string $ name , PyStringNode $ expected ): void {
452432 $ this ->response ->getBody ()->seek (0 );
453433 $ html = $ this ->response ->getBody ()->getContents ();
@@ -476,9 +456,7 @@ public function theResponseShouldContainTheInitialStateWithTheFollowingValues(st
476456 }
477457 }
478458
479- /**
480- * @Given the response should contain the initial state :name json that match with:
481- */
459+ #[Given('the response should contain the initial state :name json that match with: ' )]
482460 public function theResponseShouldContainTheInitialStateJsonThatMatchWith (string $ name , TableNode $ table ): void {
483461 $ this ->response ->getBody ()->seek (0 );
484462 $ html = $ this ->response ->getBody ()->getContents ();
@@ -499,9 +477,7 @@ public function theResponseShouldContainTheInitialStateJsonThatMatchWith(string
499477 $ this ->jsonStringMatchWith ($ actual , $ expectedValues );
500478 }
501479
502- /**
503- * @Given the following :appId app config is set
504- */
480+ #[Given('the following :appId app config is set ' )]
505481 public function setAppConfig (string $ appId , TableNode $ formData ): void {
506482 $ currentUser = $ this ->currentUser ;
507483 $ this ->setCurrentUser ('admin ' );
@@ -550,9 +526,7 @@ protected function parseText(string $text): string {
550526 return $ text ;
551527 }
552528
553- /**
554- * @Given /^run the command "(?P<command>(?:[^"]|\\")*)"$/
555- */
529+ #[Given('/^run the command "(?P<command>(?:[^"]| \\")*)"$/ ' )]
556530 public static function runCommand (string $ command ): array {
557531 $ console = static ::findParentDirContainingFile ('console.php ' );
558532 $ console .= '/console.php ' ;
@@ -622,63 +596,47 @@ private static function runBashCommand(string $command): array {
622596 ];
623597 }
624598
625- /**
626- * @Given the output of the last command should contain the following text:
627- */
599+ #[Given('the output of the last command should contain the following text: ' )]
628600 public static function theOutputOfTheLastCommandContains (PyStringNode $ text ): void {
629601 Assert::assertStringContainsString ((string ) $ text , self ::$ commandOutput , 'The output of the last command does not contain: ' . (string ) $ text );
630602 }
631603
632- /**
633- * @Given the output of the last command should be empty
634- */
604+ #[Given('the output of the last command should be empty ' )]
635605 public static function theOutputOfTheLastCommandShouldBeEmpty (): void {
636606 Assert::assertEmpty (self ::$ commandOutput , 'The output of the last command should be empty, but got: ' . self ::$ commandOutput );
637607 }
638608
639- /**
640- * @Given /^run the command "(?P<command>(?:[^"]|\\")*)" with result code (\d+)$/
641- */
609+ #[Given('/^run the command "(?P<command>(?:[^"]| \\")*)" with result code (\d+)$/ ' )]
642610 public static function runCommandWithResultCode (string $ command , int $ resultCode = 0 ): void {
643611 $ return = self ::runCommand ($ command );
644612 Assert::assertEquals ($ resultCode , $ return ['resultCode ' ], print_r ($ return , true ));
645613 }
646614
647- /**
648- * @Given /^run the bash command "(?P<command>(?:[^"]|\\")*)" with result code (\d+)$/
649- */
615+ #[Given('/^run the bash command "(?P<command>(?:[^"]| \\")*)" with result code (\d+)$/ ' )]
650616 public static function runBashCommandWithResultCode (string $ command , int $ resultCode = 0 ): void {
651617 $ return = self ::runBashCommand ($ command );
652618 Assert::assertEquals ($ resultCode , $ return ['resultCode ' ], print_r ($ return , true ));
653619 }
654620
655- /**
656- * @Given create an environment :name with value :value to be used by occ command
657- */
621+ #[Given('create an environment :name with value :value to be used by occ command ' )]
658622 public static function createAnEnvironmentWithValueToBeUsedByOccCommand (string $ name , string $ value ):void {
659623 self ::$ environments [$ name ] = $ value ;
660624 }
661625
662- /**
663- * @Given /^wait for ([0-9]+) (second|seconds)$/
664- */
626+ #[Given('/^wait for ([0-9]+) (second|seconds)$/ ' )]
665627 public function waitForXSecond (int $ seconds ): void {
666628 $ this ->startWaitFor = $ seconds ;
667629 sleep ($ seconds );
668630 }
669631
670- /**
671- * @Given /^past ([0-9]+) (second|seconds) since wait step$/
672- */
632+ #[Given('/^past ([0-9]+) (second|seconds) since wait step$/ ' )]
673633 public function pastXSecondsSinceWaitStep (int $ seconds ): void {
674634 $ currentTime = time ();
675635 $ startTime = $ currentTime - $ this ->startWaitFor ;
676636 Assert::assertGreaterThanOrEqual ($ startTime , $ currentTime , 'The current time is not greater than or equal to the start time. ' );
677637 }
678638
679- /**
680- * @AfterScenario
681- */
639+ #[AfterScenario()]
682640 public function tearDown (): void {
683641 self ::$ environments = [];
684642 foreach (self ::$ createdUsers as $ user ) {
0 commit comments