From 0492fb040d520dac30ac23944cf4e506771e9691 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Fri, 31 Mar 2023 21:23:01 +0545 Subject: [PATCH] [tests-only] fix not optional parameter after optional (#5981) --- .../features/bootstrap/FeatureContext.php | 6 ++-- .../features/bootstrap/SpacesContext.php | 30 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 7b36185db3..f2b8e19544 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -3700,15 +3700,15 @@ class FeatureContext extends BehatVariablesContext { /** * Verify that the tableNode contains expected headers * - * @param TableNode $table + * @param TableNode|null $table * @param array|null $requiredHeader * @param array|null $allowedHeader * * @return void * @throws Exception */ - public function verifyTableNodeColumns(TableNode $table, ?array $requiredHeader = [], ?array $allowedHeader = []): void { - if (\count($table->getHash()) < 1) { + public function verifyTableNodeColumns(?TableNode $table, ?array $requiredHeader = [], ?array $allowedHeader = []): void { + if ($table === null || \count($table->getHash()) < 1) { throw new Exception("Table should have at least one row."); } $tableHeaders = $table->getRows()[0]; diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 8d3d086c7f..7c87b50335 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -921,7 +921,7 @@ class SpacesContext implements Context { * @param string|null $userName * @param string|null $fileName * @param string|null $groupName - * @param TableNode $table + * @param TableNode|null $table * * @return void * @throws Exception @@ -931,7 +931,7 @@ class SpacesContext implements Context { ?string $userName = null, ?string $fileName = null, ?string $groupName = null, - TableNode $table + ?TableNode $table = null ): void { $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found"); @@ -991,17 +991,17 @@ class SpacesContext implements Context { * @param string $spaceName * @param string|null $grantedUser * @param string|null $fileName - * @param TableNode $table + * @param TableNode|null $table * * @return void - * @throws Exception|GuzzleException + * @throws GuzzleException */ public function userHasSpaceWith( string $user, string $spaceName, ?string $grantedUser = null, ?string $fileName = null, - TableNode $table + ?TableNode $table = null ): void { $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); $this->featureContext->theHTTPStatusCodeShouldBe( @@ -1042,17 +1042,17 @@ class SpacesContext implements Context { * @param string $spaceName * @param string|null $userName * @param string|null $fileName - * @param PyStringNode $schemaString + * @param PyStringNode|null $schemaString * * @return void - * @throws Exception */ public function theJsonDataFromLastResponseShouldMatch( string $spaceName, ?string $userName = null, ?string $fileName = null, - PyStringNode $schemaString + ?PyStringNode $schemaString = null ): void { + Assert::assertNotNull($schemaString, 'schema is not valid JSON'); if (isset($this->featureContext->getJsonDecodedResponseBodyContent()->value)) { $responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->value; foreach ($responseBody as $value) { @@ -1066,7 +1066,9 @@ class SpacesContext implements Context { } // substitute the value here - $schemaString = $schemaString->getRaw(); + if (\gettype($schemaString) !== 'string') { + $schemaString = $schemaString->getRaw(); + } $schemaString = $this->featureContext->substituteInLineCodes( $schemaString, $this->featureContext->getCurrentUser(), @@ -1104,22 +1106,22 @@ class SpacesContext implements Context { * @Then /^for user "([^"]*)" the JSON response of space project should match$/ * @Then /^for user "([^"]*)" the JSON response should contain space called "([^"]*)" and match$/ * @Then /^for user "([^"]*)" the JSON response should contain space called "([^"]*)" (?:owned by|granted to) "([^"]*)" (?:with description file|with space image) "([^"]*)" and match$/ - + * * @param string $user - * @param string $spaceName + * @param string|null $spaceName * @param string|null $grantedUser * @param string|null $fileName - * @param PyStringNode $schemaString + * @param PyStringNode|null $schemaString * * @return void - * @throws Exception|GuzzleException + * @throws GuzzleException */ public function forUserTheJSONDataOfTheResponseShouldMatch( string $user, ?string $spaceName = null, ?string $grantedUser = null, ?string $fileName = null, - PyStringNode $schemaString + ?PyStringNode $schemaString = null ): void { $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); $this->theJsonDataFromLastResponseShouldMatch($spaceName, $grantedUser, $fileName, $schemaString);