From f7ebbf3b75042d55908d9421ff4a3a9db357e166 Mon Sep 17 00:00:00 2001 From: Thomas Billard Date: Fri, 16 Oct 2020 16:28:56 +0200 Subject: [PATCH 1/2] update composer.json & fix behat tests --- composer.json | 6 +-- features/bootstrap/GraphqlContext.php | 2 +- features/bootstrap/HttpHeaderContext.php | 17 +-------- features/doctrine/boolean_filter.feature | 6 ++- features/doctrine/date_filter.feature | 45 +++++++++++++++-------- features/doctrine/order_filter.feature | 12 ++++-- features/doctrine/search_filter.feature | 6 ++- features/http_cache/tags.feature | 6 ++- features/hydra/collection.feature | 6 ++- features/main/circular_reference.feature | 9 ++++- features/main/content_negotiation.feature | 3 +- features/main/patch.feature | 3 +- features/openapi/docs.feature | 3 +- features/swagger/docs.feature | 6 ++- tests/ProphecyTrait.php | 4 +- 15 files changed, 78 insertions(+), 56 deletions(-) diff --git a/composer.json b/composer.json index 3a0bba7ee23..7a592efdcfe 100644 --- a/composer.json +++ b/composer.json @@ -28,9 +28,9 @@ }, "require-dev": { "behat/behat": "^3.1", - "behat/mink": "^1.7", - "behat/mink-browserkit-driver": "^1.3.1", - "behat/mink-extension": "^2.2", + "friends-of-behat/mink": "^1.7", + "friends-of-behat/mink-browserkit-driver": "^1.3.1", + "friends-of-behat/mink-extension": "^2.2", "behat/symfony2-extension": "^2.1.1", "behatch/contexts": "^3.1.0", "doctrine/annotations": "^1.7", diff --git a/features/bootstrap/GraphqlContext.php b/features/bootstrap/GraphqlContext.php index 4845fbd223c..bf34fc5fdf5 100644 --- a/features/bootstrap/GraphqlContext.php +++ b/features/bootstrap/GraphqlContext.php @@ -162,7 +162,7 @@ public function theGraphQLFieldIsDeprecatedForTheReason(string $fieldName, strin private function sendGraphqlRequest() { - $this->request->setHttpHeader('Accept', null); + $this->request->setHttpHeader('Accept', 'application/json'); $this->restContext->iSendARequestTo('GET', '/graphql?'.http_build_query($this->graphqlRequest)); } } diff --git a/features/bootstrap/HttpHeaderContext.php b/features/bootstrap/HttpHeaderContext.php index c8f5c1e4ef2..d8a011a317b 100644 --- a/features/bootstrap/HttpHeaderContext.php +++ b/features/bootstrap/HttpHeaderContext.php @@ -12,7 +12,6 @@ declare(strict_types=1); use Behat\Behat\Context\Context; -use Behat\Behat\Hook\Scope\AfterStepScope; use Behatch\HttpCall\Request; final class HttpHeaderContext implements Context @@ -25,24 +24,12 @@ public function __construct(Request $request) } /** - * Sets the default Accept HTTP header to null (workaround to artificially remove it). - * - * @AfterStep - */ - public function removeAcceptHeaderAfterRequest(AfterStepScope $event) - { - if (preg_match('/^I send a "[A-Z]+" request to ".+"/', $event->getStep()->getText())) { - $this->request->setHttpHeader('Accept', null); - } - } - - /** - * Sets the default Accept HTTP header to null (workaround to artificially remove it). + * Sets the default Accept HTTP header to application/ld+json before each scenario. * * @BeforeScenario */ public function removeAcceptHeaderBeforeScenario() { - $this->request->setHttpHeader('Accept', null); + $this->request->setHttpHeader('Accept', 'application/ld+json'); } } diff --git a/features/doctrine/boolean_filter.feature b/features/doctrine/boolean_filter.feature index e3332eea7bd..c5abf5028e2 100644 --- a/features/doctrine/boolean_filter.feature +++ b/features/doctrine/boolean_filter.feature @@ -371,7 +371,8 @@ Feature: Boolean filter on collections And the JSON node "hydra:totalItems" should be equal to 15 Scenario: Get collection filtered by non valid properties - When I send a "GET" request to "/dummies?unknown=0" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?unknown=0" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -410,7 +411,8 @@ Feature: Boolean filter on collections """ And the JSON node "hydra:totalItems" should be equal to 25 - When I send a "GET" request to "/dummies?unknown=1" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?unknown=1" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" diff --git a/features/doctrine/date_filter.feature b/features/doctrine/date_filter.feature index 067fbb14745..a1c7b430c66 100644 --- a/features/doctrine/date_filter.feature +++ b/features/doctrine/date_filter.feature @@ -6,7 +6,8 @@ Feature: Date filter on collections @createSchema Scenario: Get collection filtered by date Given there are 30 dummy objects with dummyDate - When I send a "GET" request to "/dummies?dummyDate[after]=2015-04-28" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?dummyDate[after]=2015-04-28" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -49,7 +50,8 @@ Feature: Date filter on collections } """ - When I send a "GET" request to "/dummies?dummyDate[before]=2015-04-05" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?dummyDate[before]=2015-04-05" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -92,7 +94,8 @@ Feature: Date filter on collections } """ - When I send a "GET" request to "/dummies?dummyDate[after]=2015-04-28T00:00:00%2B00:00" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?dummyDate[after]=2015-04-28T00:00:00%2B00:00" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -134,7 +137,8 @@ Feature: Date filter on collections } """ - When I send a "GET" request to "/dummies?dummyDate[before]=2015-04-05Z" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?dummyDate[before]=2015-04-05Z" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -179,7 +183,8 @@ Feature: Date filter on collections Scenario: Search for entities within a range # The order should not influence the search - When I send a "GET" request to "/dummies?dummyDate[before]=2015-04-05&dummyDate[after]=2015-04-05" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?dummyDate[before]=2015-04-05&dummyDate[after]=2015-04-05" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -216,7 +221,8 @@ Feature: Date filter on collections } """ - When I send a "GET" request to "/dummies?dummyDate[after]=2015-04-05&dummyDate[before]=2015-04-05" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?dummyDate[after]=2015-04-05&dummyDate[before]=2015-04-05" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -285,7 +291,8 @@ Feature: Date filter on collections Scenario: Get collection filtered by association date Given there are 30 dummy objects with dummyDate and relatedDummy - When I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -329,7 +336,8 @@ Feature: Date filter on collections } """ - When I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28&relatedDummy_dummyDate[after]=2015-04-28" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28&relatedDummy_dummyDate[after]=2015-04-28" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -373,7 +381,8 @@ Feature: Date filter on collections } """ - When I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28T00:00:00%2B00:00" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28T00:00:00%2B00:00" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -461,13 +470,15 @@ Feature: Date filter on collections @createSchema Scenario: Get collection filtered by date that is not a datetime including null after Given there are 3 dummydate objects with nullable dateIncludeNullAfter - When I send a "GET" request to "/dummy_dates?dateIncludeNullAfter[after]=2015-04-02" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummy_dates?dateIncludeNullAfter[after]=2015-04-02" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON node "hydra:totalItems" should be equal to 2 And the JSON node "hydra:member[0].dateIncludeNullAfter" should be equal to "2015-04-02T00:00:00+00:00" And the JSON node "hydra:member[1].dateIncludeNullAfter" should be null - When I send a "GET" request to "/dummy_dates?dateIncludeNullAfter[before]=2015-04-02" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummy_dates?dateIncludeNullAfter[before]=2015-04-02" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON node "hydra:totalItems" should be equal to 2 @@ -477,13 +488,15 @@ Feature: Date filter on collections @createSchema Scenario: Get collection filtered by date that is not a datetime including null before Given there are 3 dummydate objects with nullable dateIncludeNullBefore - When I send a "GET" request to "/dummy_dates?dateIncludeNullBefore[before]=2015-04-01" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummy_dates?dateIncludeNullBefore[before]=2015-04-01" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON node "hydra:totalItems" should be equal to 2 And the JSON node "hydra:member[0].dateIncludeNullBefore" should be equal to "2015-04-01T00:00:00+00:00" And the JSON node "hydra:member[1].dateIncludeNullBefore" should be null - When I send a "GET" request to "/dummy_dates?dateIncludeNullBefore[after]=2015-04-01" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummy_dates?dateIncludeNullBefore[after]=2015-04-01" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON node "hydra:totalItems" should be equal to 2 @@ -493,13 +506,15 @@ Feature: Date filter on collections @createSchema Scenario: Get collection filtered by date that is not a datetime including null before and after Given there are 3 dummydate objects with nullable dateIncludeNullBeforeAndAfter - When I send a "GET" request to "/dummy_dates?dateIncludeNullBeforeAndAfter[before]=2015-04-01" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummy_dates?dateIncludeNullBeforeAndAfter[before]=2015-04-01" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON node "hydra:totalItems" should be equal to 2 And the JSON node "hydra:member[0].dateIncludeNullBeforeAndAfter" should be equal to "2015-04-01T00:00:00+00:00" And the JSON node "hydra:member[1].dateIncludeNullBeforeAndAfter" should be null - When I send a "GET" request to "/dummy_dates?dateIncludeNullBeforeAndAfter[after]=2015-04-02" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummy_dates?dateIncludeNullBeforeAndAfter[after]=2015-04-02" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON node "hydra:totalItems" should be equal to 2 diff --git a/features/doctrine/order_filter.feature b/features/doctrine/order_filter.feature index 285f8557906..87cb1a7182b 100644 --- a/features/doctrine/order_filter.feature +++ b/features/doctrine/order_filter.feature @@ -599,7 +599,8 @@ Feature: Order filter on collections """ Scenario: Get collection ordered by a non valid properties and on which order filter has been enabled in whitelist mode - When I send a "GET" request to "/dummies?order[alias]=asc" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?order[alias]=asc" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -657,7 +658,8 @@ Feature: Order filter on collections } """ - When I send a "GET" request to "/dummies?order[alias]=desc" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?order[alias]=desc" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -715,7 +717,8 @@ Feature: Order filter on collections } """ - When I send a "GET" request to "/dummies?order[unknown]=asc" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?order[unknown]=asc" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -773,7 +776,8 @@ Feature: Order filter on collections } """ - When I send a "GET" request to "/dummies?order[unknown]=desc" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?order[unknown]=desc" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" diff --git a/features/doctrine/search_filter.feature b/features/doctrine/search_filter.feature index 857e0c70718..29f620d1fee 100644 --- a/features/doctrine/search_filter.feature +++ b/features/doctrine/search_filter.feature @@ -577,7 +577,8 @@ Feature: Search filter on collections """ Scenario: Get collection ordered by a non valid properties - When I send a "GET" request to "/dummies?unknown=0" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?unknown=0" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -615,7 +616,8 @@ Feature: Search filter on collections } """ - When I send a "GET" request to "/dummies?unknown=1" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?unknown=1" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" diff --git a/features/http_cache/tags.feature b/features/http_cache/tags.feature index e620b3d3253..994268d1782 100644 --- a/features/http_cache/tags.feature +++ b/features/http_cache/tags.feature @@ -64,13 +64,15 @@ Feature: Cache invalidation through HTTP Cache tags And "/relation_embedders,/relation_embedders/1,/related_dummies/1" IRIs should be purged Scenario: Create two Relation2 - When I add "Content-Type" header equal to "application/ld+json" + When I add "Accept" header equal to "application/ld+json" + And I add "Content-Type" header equal to "application/ld+json" And I send a "POST" request to "/relation2s" with body: """ { } """ - When I add "Content-Type" header equal to "application/ld+json" + When I add "Accept" header equal to "application/ld+json" + And I add "Content-Type" header equal to "application/ld+json" And I send a "POST" request to "/relation2s" with body: """ { diff --git a/features/hydra/collection.feature b/features/hydra/collection.feature index ee92c4002e7..00fc3d84ee7 100644 --- a/features/hydra/collection.feature +++ b/features/hydra/collection.feature @@ -398,7 +398,8 @@ Feature: Collections support @createSchema Scenario: Allow passing 0 to `itemsPerPage` - When I send a "GET" request to "/dummies?itemsPerPage=0" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?itemsPerPage=0" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -433,7 +434,8 @@ Feature: Collections support } """ - When I send a "GET" request to "/dummies?itemsPerPage=0&page=2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/dummies?itemsPerPage=0&page=2" Then the response status code should be 400 And the JSON node "hydra:description" should be equal to "Page should not be greater than 1 if limit is equal to 0" diff --git a/features/main/circular_reference.feature b/features/main/circular_reference.feature index f53d44d9164..13f0a0ddd74 100644 --- a/features/main/circular_reference.feature +++ b/features/main/circular_reference.feature @@ -5,11 +5,13 @@ Feature: Circular references handling @createSchema Scenario: Create a circular reference - When I add "Content-Type" header equal to "application/ld+json" + When I add "Accept" header equal to "application/ld+json" + And I add "Content-Type" header equal to "application/ld+json" And I send a "POST" request to "/circular_references" with body: """ {} """ + And I add "Accept" header equal to "application/ld+json" And I add "Content-Type" header equal to "application/ld+json" And I send a "PUT" request to "/circular_references/1" with body: """ @@ -34,11 +36,13 @@ Feature: Circular references handling """ Scenario: Fetch circular reference - When I add "Content-Type" header equal to "application/ld+json" + When I add "Accept" header equal to "application/ld+json" + And I add "Content-Type" header equal to "application/ld+json" And I send a "POST" request to "/circular_references" with body: """ {} """ + And I add "Accept" header equal to "application/ld+json" And I add "Content-Type" header equal to "application/ld+json" And I send a "PUT" request to "/circular_references/2" with body: """ @@ -67,6 +71,7 @@ Feature: Circular references handling "children": [] } """ + And I add "Accept" header equal to "application/ld+json" And I send a "GET" request to "/circular_references/1" Then the response status code should be 200 And the JSON should be equal to: diff --git a/features/main/content_negotiation.feature b/features/main/content_negotiation.feature index 71033af1f74..7aaa2a774db 100644 --- a/features/main/content_negotiation.feature +++ b/features/main/content_negotiation.feature @@ -33,7 +33,8 @@ Feature: Content Negotiation support """ Scenario: Retrieve a collection in XML using the .xml URL - When I send a "GET" request to "/dummies.xml" + When I add "Accept" header equal to "application/xml" + And I send a "GET" request to "/dummies.xml" Then the response status code should be 200 And the header "Content-Type" should be equal to "application/xml; charset=utf-8" And the response should be equal to diff --git a/features/main/patch.feature b/features/main/patch.feature index c2f37f67bb6..22dbd5dd0ea 100644 --- a/features/main/patch.feature +++ b/features/main/patch.feature @@ -9,7 +9,8 @@ Feature: Sending PATCH requets """ {"name": "Hello"} """ - When I add "Content-Type" header equal to "application/ld+json" + When I add "Accept" header equal to "application/ld+json" + And I add "Content-Type" header equal to "application/ld+json" And I send a "GET" request to "/patch_dummies/1" Then the header "Accept-Patch" should be equal to "application/merge-patch+json, application/vnd.api+json" diff --git a/features/openapi/docs.feature b/features/openapi/docs.feature index ec8806eaafe..dc3cd52933d 100644 --- a/features/openapi/docs.feature +++ b/features/openapi/docs.feature @@ -5,7 +5,8 @@ Feature: Documentation support @createSchema Scenario: Retrieve the OpenAPI documentation - Given I send a "GET" request to "/docs.json?spec_version=3" + Given I add "Accept" header equal to "application/json" + And I send a "GET" request to "/docs.json?spec_version=3" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/json; charset=utf-8" diff --git a/features/swagger/docs.feature b/features/swagger/docs.feature index c9e0111fee7..79b18b9fbc7 100644 --- a/features/swagger/docs.feature +++ b/features/swagger/docs.feature @@ -5,7 +5,8 @@ Feature: Documentation support @createSchema Scenario: Retrieve the Swagger/OpenAPI documentation - Given I send a "GET" request to "/docs.json" + Given I add "Accept" header equal to "application/json" + And I send a "GET" request to "/docs.json" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/json; charset=utf-8" @@ -127,7 +128,8 @@ Feature: Documentation support And I should see text matching "2.0" Scenario: Retrieve the Swagger/OpenAPI documentation with API Gateway compatibility - Given I send a "GET" request to "/docs.json?api_gateway=true" + Given I add "Accept" header equal to "application/json" + And I send a "GET" request to "/docs.json?api_gateway=true" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/json; charset=utf-8" diff --git a/tests/ProphecyTrait.php b/tests/ProphecyTrait.php index 439608d5a4b..e9058776377 100644 --- a/tests/ProphecyTrait.php +++ b/tests/ProphecyTrait.php @@ -110,9 +110,7 @@ private function countProphecyAssertions(): void $this->prophecyAssertionsCounted = true; foreach ($this->prophet->getProphecies() as $objectProphecy) { - /** - * @var MethodProphecy[] $methodProphecies - */ + /** @var MethodProphecy[] $methodProphecies */ foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { \assert($methodProphecy instanceof MethodProphecy); From e12f8f006c88c37b23fb07b70c7e171602172c9a Mon Sep 17 00:00:00 2001 From: Thomas Billard Date: Thu, 22 Oct 2020 22:50:14 +0200 Subject: [PATCH 2/2] WIP revert to behat/mink --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7a592efdcfe..06f8e9c6a91 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "require-dev": { "behat/behat": "^3.1", - "friends-of-behat/mink": "^1.7", + "behat/mink": "^1.7", "friends-of-behat/mink-browserkit-driver": "^1.3.1", "friends-of-behat/mink-extension": "^2.2", "behat/symfony2-extension": "^2.1.1",