diff --git a/README.md b/README.md index 9082941..d8ae309 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,11 @@ vendor/bin/behat -dl When as user :user When user :user exists When sending :verb to :url +When the response should be a JSON array with the following mandatory values When the response should contain the initial state :name with the following values: When /^set the email of user "([^"]*)" to "([^"]*)"$/ When sending :verb to ocs :url When the response should have a status code :code -When the response should be a JSON array with the following mandatory values When the following :appId app config is set ``` @@ -81,3 +81,20 @@ When sending "post" to ocs "/apps/libresign/api/v1/request-signature" ``` By this way you will receive on your controller method 2 values, status as integer and file as array. + +## Parse initial state +If you need to parse the initial state to use placeholder or get any value from current initial state, implement a method `parseText` like this: +```php +protected function parseText(string $text): string { + $patterns = [ + '//', + '//', + ]; + $replacements = [ + $this->signer['sign_uuid'] ?? null, + $this->file['uuid'] ?? $this->getFileUuidFromText($text), + ]; + $text = preg_replace($patterns, $replacements, $text); + return $text; +} +``` diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 291ffa9..5b27c47 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -1,8 +1,10 @@ getLastRequest(); + // Mock response to be equal to body of request + $this->mockServer->setDefaultResponse(new MockWebServerResponse( + json_encode($lastRequest->getParsedInput()) + )); + parent::theResponseShouldBeAJsonArrayWithTheFollowingMandatoryValues($table); + } + /** * @inheritDoc */ diff --git a/features/test.feature b/features/test.feature index 1b9fd62..9a266f2 100644 --- a/features/test.feature +++ b/features/test.feature @@ -1,31 +1,69 @@ Feature: Test this extension - Scenario: Check if all steps of this extension is working fine + Scenario: Test user Given as user "test" - And user test exists - And sending "POST" to "/" + Then user test exists + + Scenario: Test POST with success + Given sending "POST" to "/" | status | 1 | - And the response should contain the initial state "appid-string" with the following values: + + Scenario: Test response of POST is numeric + When sending "POST" to "/" + | status | 1 | + Then the response should be a JSON array with the following mandatory values + | status | 1 | + + Scenario: Test response of POST is string + When sending "POST" to "/" + | status | "string" | + Then the response should be a JSON array with the following mandatory values + | status | "string" | + + Scenario: Test response of POST is boolean + When sending "POST" to "/" + | status | true | + Then the response should be a JSON array with the following mandatory values + | status | true | + + Scenario: Test response of POST is json + When sending "POST" to "/" + | status | (string){"string": "test"} | + Then the response should be a JSON array with the following mandatory values + | status | {"string": "test"} | + + Scenario: Test initial state with string + Then the response should contain the initial state "appid-string" with the following values: """ default """ - And the response should contain the initial state "appid-string" with the following values: + + Scenario: Test initial state with boolean + Then the response should contain the initial state "appid-string" with the following values: """ true """ - And the response should contain the initial state "appid-string" with the following values: + + Scenario: Test initial state with null + Then the response should contain the initial state "appid-string" with the following values: """ null """ - And the response should contain the initial state "appid-string" with the following values: + + Scenario: Test initial state with empty + Then the response should contain the initial state "appid-string" with the following values: """ """ - And the response should contain the initial state "appid-json-object" with the following values: + + Scenario: Test initial state with json + Then the response should contain the initial state "appid-json-object" with the following values: """ { "fruit": "orange" } """ - And the response should contain the initial state "appid-json-array" with the following values: + + Scenario: Test initial state with array + Then the response should contain the initial state "appid-json-array" with the following values: """ [ "orange" diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index fc1051d..5680e20 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -245,7 +245,11 @@ public function theResponseShouldBeAJsonArrayWithTheFollowingMandatoryValues(Tab $expectedValues = $table->getColumnsHash(); $realResponseArray = json_decode($this->response->getBody()->getContents(), true); foreach ($expectedValues as $value) { - if ($this->isJson($realResponseArray[$value['key']]) || is_bool($realResponseArray[$value['key']])) { + if (is_bool($realResponseArray[$value['key']]) + || is_iterable($realResponseArray[$value['key']]) + || is_numeric($realResponseArray[$value['key']]) + || (is_string($realResponseArray[$value['key']]) && $this->isJson($realResponseArray[$value['key']])) + ) { $actualJson = json_encode($realResponseArray[$value['key']]); Assert::assertJsonStringEqualsJsonString($value['value'], $actualJson, 'Key: ' . $value['key']); continue; diff --git a/vendor-bin/psalm/composer.lock b/vendor-bin/psalm/composer.lock index a2252b5..4a0874d 100644 --- a/vendor-bin/psalm/composer.lock +++ b/vendor-bin/psalm/composer.lock @@ -909,16 +909,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.21.0", + "version": "1.21.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c" + "reference": "e560a3eb5e76b35d6d92377e5abb6887c1c13c95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6df62b08faef4f899772bc7c3bbabb93d2b7a21c", - "reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/e560a3eb5e76b35d6d92377e5abb6887c1c13c95", + "reference": "e560a3eb5e76b35d6d92377e5abb6887c1c13c95", "shasum": "" }, "require": { @@ -949,9 +949,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.1" }, - "time": "2023-05-17T13:13:44+00:00" + "time": "2023-05-29T11:55:57+00:00" }, { "name": "psr/container",