Skip to content

Commit 7a447f2

Browse files
authored
Merge pull request #98 from LibreSign/chore/replace-annotation-by-attribute
chore: replace annotation by attribute
2 parents a796a67 + 930d2bf commit 7a447f2

3 files changed

Lines changed: 37 additions & 63 deletions

File tree

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ vendor/bin/behat -dl
4848
```
4949

5050
```gherkin
51-
When as user :user
52-
When user :user exists
53-
When sending :verb to :url
54-
When the response should be a JSON array with the following mandatory values
55-
When /^set the display name of user "([^"]*)" to "([^"]*)"$/
56-
When /^set the email of user "([^"]*)" to "([^"]*)"$/
57-
When sending :verb to ocs :url
58-
When the response should have a status code :code
59-
When fetch field :path from prevous JSON response
60-
When the response should contain the initial state :name with the following values:
61-
When the response should contain the initial state :name json that match with:
62-
When the following :appId app config is set
51+
Given as user :user
52+
Given user :user exists
53+
Given sending :verb to :url
54+
Given the response should be a JSON array with the following mandatory values
55+
Given /^set the display name of user "([^"]*)" to "([^"]*)"$/
56+
Given /^set the email of user "([^"]*)" to "([^"]*)"$/
57+
Given sending :verb to ocs :url
58+
Given the response should have a status code :code
59+
Given fetch field :path from prevous JSON response
60+
Given the response should contain the initial state :name with the following values:
61+
Given the response should contain the initial state :name json that match with:
62+
Given the following :appId app config is set
6363
```
6464

6565
## Tips
@@ -69,7 +69,7 @@ To send a json value as string, prefix the json string with (string)
6969

7070
**Example**:
7171
```gherkin
72-
When sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/appname/propertyname"
72+
Given sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/appname/propertyname"
7373
| value | (string){"enabled":true} |
7474
```
7575

@@ -78,7 +78,7 @@ To send a value as array, you can set a json string and the json string will be
7878

7979
**Example**:
8080
```gherkin
81-
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
81+
Given sending "post" to ocs "/apps/libresign/api/v1/request-signature"
8282
| status | 1 |
8383
| file | {"base64":""} |
8484
```
@@ -125,7 +125,7 @@ You can use [jq](https://jqlang.github.io/jq/manual/) expression casting to chec
125125
Example:
126126

127127
```gherkin
128-
When set the response to:
128+
Given set the response to:
129129
"""
130130
{
131131
"Foo": {

features/bootstrap/FeatureContext.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Behat\Gherkin\Node\PyStringNode;
44
use Behat\Gherkin\Node\TableNode;
5+
use Behat\Step\Given;
56
use donatj\MockWebServer\MockWebServer;
67
use donatj\MockWebServer\RequestInfo;
78
use donatj\MockWebServer\Response as MockWebServerResponse;
@@ -78,9 +79,7 @@ public function sendRequest(string $verb, string $url, $body = null, array $head
7879
}
7980
}
8081

81-
/**
82-
* @when set the response to:
83-
*/
82+
#[Given('set the response to:')]
8483
public function setTheResponseTo(PyStringNode $response): void {
8584
// Mock response to be equal to body of request
8685
$this->mockServer->setDefaultResponse(new MockWebServerResponse(

src/NextcloudApiContext.php

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use Behat\Behat\Context\Context;
66
use Behat\Gherkin\Node\PyStringNode;
77
use Behat\Gherkin\Node\TableNode;
8+
use Behat\Hook\AfterScenario;
9+
use Behat\Hook\BeforeScenario;
10+
use Behat\Hook\BeforeSuite;
11+
use Behat\Step\Given;
812
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
913
use DOMDocument;
1014
use 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

Comments
 (0)