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 ;
@@ -48,9 +52,7 @@ public function __construct(?array $parameters = []) {
4852 }
4953 }
5054
51- /**
52- * @BeforeSuite
53- */
55+ #[BeforeSuite()]
5456 public static function beforeSuite (BeforeSuiteScope $ scope ):void {
5557 $ whoami = (string ) exec ('whoami ' );
5658 if (get_current_user () !== $ whoami ) {
@@ -63,25 +65,17 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
6365 }
6466 }
6567
66- /**
67- * @BeforeScenario
68- */
68+ #[BeforeScenario()]
6969 public function setUp (): void {
7070 $ this ->createdUsers = [];
7171 }
7272
73- /**
74- * @When as user :user
75- * @param string $user
76- */
73+ #[Given('as user :user ' )]
7774 public function setCurrentUser (string $ user ): void {
7875 $ this ->currentUser = $ user ;
7976 }
8077
81- /**
82- * @When user :user exists
83- * @param string $user
84- */
78+ #[Given('user :user exists ' )]
8579 public function assureUserExists (string $ user ): void {
8680 $ response = $ this ->userExists ($ user );
8781 if ($ response ->getStatusCode () !== 200 ) {
@@ -121,7 +115,7 @@ protected function createUser(string $user): void {
121115 $ this ->setCurrentUser ($ currentUser );
122116 }
123117
124- /** @When / ^set the display name of user "([^"]*)" to "([^"]*)"$/ */
118+ #[Given( ' / ^set the display name of user "([^"]*)" to "([^"]*)"$/' )]
125119 public function setUserDisplayName (string $ user , ?string $ displayName = null ): void {
126120 $ currentUser = $ this ->currentUser ;
127121 $ this ->setCurrentUser ('admin ' );
@@ -133,7 +127,7 @@ public function setUserDisplayName(string $user, ?string $displayName = null): v
133127 $ this ->setCurrentUser ($ currentUser );
134128 }
135129
136- /** @When / ^set the email of user "([^"]*)" to "([^"]*)"$/ */
130+ #[Given( ' / ^set the email of user "([^"]*)" to "([^"]*)"$/' )]
137131 public function setUserEmail (string $ user , string $ email ): void {
138132 $ currentUser = $ this ->currentUser ;
139133 $ this ->setCurrentUser ('admin ' );
@@ -145,24 +139,24 @@ public function setUserEmail(string $user, string $email): void {
145139 }
146140
147141 /**
148- * @When sending :verb to ocs :url
149142 * @param string $verb
150143 * @param string $url
151144 * @param TableNode|array|null $body
152145 */
146+ #[Given('sending :verb to ocs :url ' )]
153147 public function sendOCSRequest (string $ verb , string $ url , $ body = null , array $ headers = [], array $ options = []): void {
154148 $ url = '/ocs/v2.php ' . $ url ;
155149 $ headers ['OCS-ApiRequest ' ] = 'true ' ;
156150 $ this ->sendRequest ($ verb , $ url , $ body , $ headers , $ options );
157151 }
158152
159153 /**
160- * @When sending :verb to :url
161154 * @param string $verb
162155 * @param string $url
163156 * @param TableNode|array|null $body
164157 * @param array $headers
165158 */
159+ #[Given('sending :verb to :url ' )]
166160 public function sendRequest (string $ verb , string $ url , $ body = null , array $ headers = [], array $ options = []): void {
167161 if (!str_starts_with ($ url , '/ ' )) {
168162 $ url = '/ ' . $ url ;
@@ -238,30 +232,23 @@ protected function getUserCookieJar(string $user): CookieJar {
238232 return $ this ->cookieJars [$ user ];
239233 }
240234
241- /**
242- * @param ResponseInterface $response
243- * @param int $statusCode
244- * @param string $message
245- */
246235 protected function assertStatusCode (ResponseInterface $ response , int $ statusCode , string $ message = '' ): void {
247236 Assert::assertEquals ($ statusCode , $ response ->getStatusCode (), $ message );
248237 }
249238
250239 /**
251- * @When the response should have a status code :code
252- * @param string $code
253240 * @throws \InvalidArgumentException
254241 */
255- public function theResponseShouldHaveStatusCode ($ code ): void {
242+ #[Given('the response should have a status code :code ' )]
243+ public function theResponseShouldHaveStatusCode (string $ code ): void {
256244 $ currentCode = $ this ->response ->getStatusCode ();
257245 Assert::assertEquals ($ code , $ currentCode , $ this ->response ->getBody ()->getContents ());
258246 }
259247
260248 /**
261- * @When the response should be a JSON array with the following mandatory values
262- * @param TableNode $table
263249 * @throws \InvalidArgumentException
264250 */
251+ #[Given('the response should be a JSON array with the following mandatory values ' )]
265252 public function theResponseShouldBeAJsonArrayWithTheFollowingMandatoryValues (TableNode $ table ): void {
266253 $ this ->response ->getBody ()->seek (0 );
267254 $ expectedValues = $ table ->getColumnsHash ();
@@ -335,9 +322,7 @@ private function validateAsJsonQuery(string $expected, string $actual): void {
335322 Assert::assertTrue ($ result , 'The jq " ' . $ expected . '" do not match with: ' . $ actual );
336323 }
337324
338- /**
339- * @When fetch field :path from prevous JSON response
340- */
325+ #[Given('fetch field :path from prevous JSON response ' )]
341326 public function fetchFieldFromPreviousJsonResponse (string $ path ): void {
342327 $ this ->response ->getBody ()->seek (0 );
343328 $ responseArray = json_decode ($ this ->response ->getBody ()->getContents (), true );
@@ -359,9 +344,7 @@ public function fetchFieldFromPreviousJsonResponse(string $path): void {
359344 $ this ->fields [$ path ] = $ value ;
360345 }
361346
362- /**
363- * @When the response should contain the initial state :name with the following values:
364- */
347+ #[Given('the response should contain the initial state :name with the following values: ' )]
365348 public function theResponseShouldContainTheInitialStateWithTheFollowingValues (string $ name , PyStringNode $ expected ): void {
366349 $ this ->response ->getBody ()->seek (0 );
367350 $ html = $ this ->response ->getBody ()->getContents ();
@@ -390,9 +373,7 @@ public function theResponseShouldContainTheInitialStateWithTheFollowingValues(st
390373 }
391374 }
392375
393- /**
394- * @When the response should contain the initial state :name json that match with:
395- */
376+ #[Given('the response should contain the initial state :name json that match with: ' )]
396377 public function theResponseShouldContainTheInitialStateJsonThatMatchWith (string $ name , TableNode $ table ): void {
397378 $ this ->response ->getBody ()->seek (0 );
398379 $ html = $ this ->response ->getBody ()->getContents ();
@@ -413,11 +394,7 @@ public function theResponseShouldContainTheInitialStateJsonThatMatchWith(string
413394 $ this ->jsonStringMatchWith ($ actual , $ expectedValues );
414395 }
415396
416- /**
417- * @When the following :appId app config is set
418- *
419- * @param TableNode $formData
420- */
397+ #[Given('the following :appId app config is set ' )]
421398 public function setAppConfig (string $ appId , TableNode $ formData ): void {
422399 $ currentUser = $ this ->currentUser ;
423400 $ this ->setCurrentUser ('admin ' );
@@ -462,9 +439,7 @@ protected function parseText(string $text): string {
462439 return $ text ;
463440 }
464441
465- /**
466- * @AfterScenario
467- */
442+ #[AfterScenario()]
468443 public function tearDown (): void {
469444 foreach ($ this ->createdUsers as $ user ) {
470445 $ this ->deleteUser ($ user );
0 commit comments