From 42269de33a44538c2d7cba3a519c7861ecac4e76 Mon Sep 17 00:00:00 2001 From: Tomasz Grochowski Date: Tue, 23 Nov 2021 10:40:14 +0100 Subject: [PATCH] Move tests inside src so contexts can be reusable in other projects --- behat.yml.dist | 2 +- {tests => src}/Behat/Client/GraphqlClient.php | 32 +++++--- .../Behat/Client/GraphqlClientInterface.php | 4 +- .../Context/GraphqlApiPlatformContext.php | 51 +++++-------- .../Behat/Context/Shop/AddressContext.php | 9 ++- .../Behat/Context/Shop/CartContext.php | 8 +- .../Behat/Context/Shop/CheckoutContext.php | 6 +- .../Behat/Context/Shop/CustomerContext.php | 20 +++-- .../Behat/Context/Shop/LoginContext.php | 6 +- .../Behat/Context/Shop/ProductContext.php | 8 +- .../Context/Shop/RegistrationContext.php | 8 +- src/Behat/Context/Shop/TaxonContext.php | 70 ++++++++++++++++++ .../Behat/Model/OperationRequest.php | 2 +- .../Behat/Model/OperationRequestInterface.php | 2 +- {tests => src}/Behat/Resources/suites.yml | 0 .../suites/account/changing_password.yaml | 6 +- .../suites/account/creating_account.yaml | 8 +- .../suites/account/editing_account.yaml | 8 +- .../suites/account/managing_addresses.yaml | 8 +- .../suites/cart/place_order_as_customer.yaml | 14 ++-- .../suites/cart/place_order_as_guest.yaml | 12 +-- .../cart/place_order_as_guest_customer.yaml | 14 ++-- .../Behat/Service/ApiSecurityService.php | 9 ++- src/Resources/config/services.xml | 2 +- .../Resources/services/behat}/clients.xml | 4 +- src/Resources/services/behat/contexts.xml | 73 +++++++++++++++++++ tests/Behat/Resources/services.xml | 8 -- tests/Behat/Resources/services/contexts.xml | 67 ----------------- 28 files changed, 270 insertions(+), 191 deletions(-) rename {tests => src}/Behat/Client/GraphqlClient.php (90%) rename {tests => src}/Behat/Client/GraphqlClientInterface.php (91%) rename {tests => src}/Behat/Context/GraphqlApiPlatformContext.php (82%) rename {tests => src}/Behat/Context/Shop/AddressContext.php (94%) rename {tests => src}/Behat/Context/Shop/CartContext.php (96%) rename {tests => src}/Behat/Context/Shop/CheckoutContext.php (95%) rename {tests => src}/Behat/Context/Shop/CustomerContext.php (89%) rename {tests => src}/Behat/Context/Shop/LoginContext.php (84%) rename {tests => src}/Behat/Context/Shop/ProductContext.php (90%) rename {tests => src}/Behat/Context/Shop/RegistrationContext.php (92%) create mode 100644 src/Behat/Context/Shop/TaxonContext.php rename {tests => src}/Behat/Model/OperationRequest.php (98%) rename {tests => src}/Behat/Model/OperationRequestInterface.php (95%) rename {tests => src}/Behat/Resources/suites.yml (100%) rename {tests => src}/Behat/Resources/suites/account/changing_password.yaml (67%) rename {tests => src}/Behat/Resources/suites/account/creating_account.yaml (61%) rename {tests => src}/Behat/Resources/suites/account/editing_account.yaml (63%) rename {tests => src}/Behat/Resources/suites/account/managing_addresses.yaml (60%) rename {tests => src}/Behat/Resources/suites/cart/place_order_as_customer.yaml (60%) rename {tests => src}/Behat/Resources/suites/cart/place_order_as_guest.yaml (63%) rename {tests => src}/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml (60%) rename {tests => src}/Behat/Service/ApiSecurityService.php (84%) rename {tests/Behat/Resources/services => src/Resources/services/behat}/clients.xml (79%) create mode 100755 src/Resources/services/behat/contexts.xml delete mode 100644 tests/Behat/Resources/services.xml delete mode 100755 tests/Behat/Resources/services/contexts.xml diff --git a/behat.yml.dist b/behat.yml.dist index b3cd0975..7ce85611 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -1,6 +1,6 @@ imports: - vendor/sylius/sylius/src/Sylius/Behat/Resources/config/suites.yml - - tests/Behat/Resources/suites.yml + - src/Behat/Resources/suites.yml default: extensions: diff --git a/tests/Behat/Client/GraphqlClient.php b/src/Behat/Client/GraphqlClient.php similarity index 90% rename from tests/Behat/Client/GraphqlClient.php rename to src/Behat/Client/GraphqlClient.php index e6a512d6..36030a57 100644 --- a/tests/Behat/Client/GraphqlClient.php +++ b/src/Behat/Client/GraphqlClient.php @@ -8,8 +8,10 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Client; +namespace BitBag\SyliusGraphqlPlugin\Behat\Client; +use BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequest; +use BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Exception; use const JSON_ERROR_NONE; use RecursiveArrayIterator; @@ -21,8 +23,6 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequest; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Webmozart\Assert\Assert; final class GraphqlClient implements GraphqlClientInterface @@ -101,7 +101,10 @@ public function prepareQuery( public function getLastOperationRequest(): ?OperationRequestInterface { - return $this->sharedStorage->get(self::GRAPHQL_OPERATION); + /** @var OperationRequestInterface|null $operation */ + $operation = $this->sharedStorage->get(self::GRAPHQL_OPERATION); + + return $operation; } public function addAuthorization(): void @@ -125,6 +128,7 @@ public function send(): Response $this->client->setServerParameter('HTTP_HOST', (string) $this->sharedStorage->get('hostname')); } + /** @var OperationRequest $operation */ $operation = $this->getLastOperationRequest(); $this->sendJsonRequest( @@ -149,12 +153,16 @@ public function saveLastResponse(Response $response): void public function getLastResponse(): ?JsonResponse { - return $this->sharedStorage->get(self::LAST_GRAPHQL_RESPONSE); + /** @var JsonResponse|null $jsonResponse */ + $jsonResponse = $this->sharedStorage->get(self::LAST_GRAPHQL_RESPONSE); + + return $jsonResponse; } -/** @throws Exception */ + /** @throws Exception */ public function getLastResponseArrayContent(): array { + /** @var JsonResponse $response */ $response = $this->getLastResponse(); $json = $this->getJsonFromResponse($response); if ($json === null) { @@ -169,6 +177,8 @@ public function getJsonFromResponse(Response $response): ?array $content = $response->getContent(); Assert::string($content); + $jsonData = []; + try { /** @var array $jsonData */ $jsonData = json_decode($content, true); @@ -183,23 +193,26 @@ public function getJsonFromResponse(Response $response): ?array return null; } -/** @throws Exception */ + /** @throws Exception */ public function flattenArray(array $responseArray): array { $this->checkIfResponseProperlyFormatted($responseArray); $array = []; if ($this->isDataSectionPresentInResponse($responseArray)) { + Assert::isArray($responseArray['data']); /** @var array $array */ $array = reset($responseArray['data']); } if ($this->isErrorSectionPresentInResponse($responseArray)) { + Assert::isArray($responseArray['errors']); /** @var array $array */ $array = reset($responseArray['errors']); } $recursiveIteratorIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::CHILD_FIRST); $result = []; + /** @psalm-suppress MixedAssignment */ foreach ($recursiveIteratorIterator as $value) { $keys = []; foreach (range(0, $recursiveIteratorIterator->getDepth()) as $depth) { @@ -220,7 +233,9 @@ private function sendJsonRequest( bool $changeHistory = true ): Crawler { $content = json_encode($parameters); + Assert::string($content); $this->setJsonServerHeaders(); + return $this->client->request($method, $uri, [], [], $server, $content, $changeHistory); } @@ -235,9 +250,6 @@ public function getValueAtKey(string $key) $flatResponse = $this->flattenArray($arrayContent); if (!array_key_exists($key, $flatResponse)) { - $message = array_key_exists('debugMessage', $flatResponse) ? $flatResponse['debugMessage'] : $flatResponse; - $trace = array_key_exists('trace', $flatResponse) ? $flatResponse['trace'] : $flatResponse; - throw new Exception( sprintf( "Last response did not have any key named %s \n%s", diff --git a/tests/Behat/Client/GraphqlClientInterface.php b/src/Behat/Client/GraphqlClientInterface.php similarity index 91% rename from tests/Behat/Client/GraphqlClientInterface.php rename to src/Behat/Client/GraphqlClientInterface.php index 91ccab54..67737b80 100644 --- a/tests/Behat/Client/GraphqlClientInterface.php +++ b/src/Behat/Client/GraphqlClientInterface.php @@ -8,12 +8,12 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Client; +namespace BitBag\SyliusGraphqlPlugin\Behat\Client; +use BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; interface GraphqlClientInterface { diff --git a/tests/Behat/Context/GraphqlApiPlatformContext.php b/src/Behat/Context/GraphqlApiPlatformContext.php similarity index 82% rename from tests/Behat/Context/GraphqlApiPlatformContext.php rename to src/Behat/Context/GraphqlApiPlatformContext.php index 89204e64..3d26eef8 100644 --- a/tests/Behat/Context/GraphqlApiPlatformContext.php +++ b/src/Behat/Context/GraphqlApiPlatformContext.php @@ -2,16 +2,14 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context; use Behat\Behat\Context\Context; -use Behat\Gherkin\Node\PyStringNode; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; +use BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Exception; use Sylius\Behat\Service\SharedStorageInterface; use Symfony\Component\HttpFoundation\JsonResponse; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Webmozart\Assert\Assert; /** Context for GraphQL. */ @@ -32,7 +30,7 @@ public function __construct(GraphqlClientInterface $client, SharedStorageInterfa */ public function getBooleanFromString(string $boolean): bool { - return (bool)$boolean; + return (bool) $boolean; } /** @@ -68,25 +66,6 @@ public function iShouldReceiveAJsonResponse(): void } } - /** - * @When I should see following response: - * - * @throws Exception - */ - public function iShouldSeeFollowingResponse(PyStringNode $json): bool - { - /** @var array $expected */ - $expected = json_decode($json->getRaw(), true); - /** @var array $lastResponse */ - $lastResponse = $this->sharedStorage->get(GraphqlClient::LAST_GRAPHQL_RESPONSE); - $result_array = $this->differ->diff($expected, $lastResponse); - if (empty($result_array)) { - return true; - } - - throw new Exception('Expected response doest match last one'); - } - /** * @param mixed $value * @When I set :key field to :value @@ -122,16 +101,18 @@ public function iSetKeyFieldToPreviouslySavedValue(string $key, string $name, st } /** - * @var mixed * @Then I set :sharedStorageKey object :propertyName property to :value + * + * @param mixed $value */ public function iSetObjectPropertyToValue(string $sharedStorageKey, string $propertyName, $value): void { try { - $storageValue = (array)$this->sharedStorage->get($sharedStorageKey); + $storageValue = (array) $this->sharedStorage->get($sharedStorageKey); } catch (\InvalidArgumentException $e) { $storageValue = []; } + /** @psalm-suppress MixedAssignment */ $storageValue[$propertyName] = $value; $this->sharedStorage->set($sharedStorageKey, $storageValue); } @@ -177,29 +158,30 @@ public function thatResponseShouldContainKeyWithValue(string $key, $value): void /** * @param mixed $value * - * @return mixed + * @return bool|float|int|string|array */ private function castToType($value, string $type = null) { switch ($type) { case 'bool': - $value = (bool)$value; + $value = (bool) $value; break; case 'float': - $value = (float)$value; + $value = (float) $value; break; case 'int': - $value = (int)$value; + $value = (int) $value; break; case 'string': - $value = (string)$value; + $value = (string) $value; break; default: - return $value; + $value = is_array($value) ? (array) $value: (string) $value; + break; } return $value; @@ -230,6 +212,7 @@ public function iShouldSeeFollowingErrorMessage(string $message): bool */ public function iSaveValueAtKeyOfThisModelResponse(string $key, string $name, ?string $type = null): void { + /** @psalm-suppress MixedAssignment */ $value = $this->client->getValueAtKey($key); $value = $this->castToType($value, $type); $this->sharedStorage->set($name, $value); @@ -237,6 +220,8 @@ public function iSaveValueAtKeyOfThisModelResponse(string $key, string $name, ?s private function getJsonFromResponse(string $response): ?array { + $jsonData = []; + try { /** @var array $jsonData */ $jsonData = json_decode($response, true); diff --git a/tests/Behat/Context/Shop/AddressContext.php b/src/Behat/Context/Shop/AddressContext.php similarity index 94% rename from tests/Behat/Context/Shop/AddressContext.php rename to src/Behat/Context/Shop/AddressContext.php index 3d233993..1e2d3d65 100644 --- a/tests/Behat/Context/Shop/AddressContext.php +++ b/src/Behat/Context/Shop/AddressContext.php @@ -8,18 +8,19 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use ApiPlatform\Core\Api\IriConverterInterface; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\Address; use Sylius\Component\Core\Model\Customer; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\Core\Repository\AddressRepositoryInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; +use Webmozart\Assert\Assert; final class AddressContext implements Context { @@ -138,6 +139,8 @@ public function customerHasAnAddress(string $email): void /** @var ShopUserInterface|null $user */ $user = $this->userRepository->findOneBy(['username' => $email]); + Assert::notNull($user); + /** @var Customer $customer */ $customer = $user->getCustomer(); $address = new Address(); diff --git a/tests/Behat/Context/Shop/CartContext.php b/src/Behat/Context/Shop/CartContext.php similarity index 96% rename from tests/Behat/Context/Shop/CartContext.php rename to src/Behat/Context/Shop/CartContext.php index 4ec58af8..51c49669 100644 --- a/tests/Behat/Context/Shop/CartContext.php +++ b/src/Behat/Context/Shop/CartContext.php @@ -8,15 +8,15 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use ApiPlatform\Core\Api\IriConverterInterface; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Webmozart\Assert\Assert; final class CartContext implements Context @@ -256,7 +256,7 @@ public function iPrepareOperationChoosePredefinedAddressAsBilling(string $addres /** * @Then total price for items should equal to :price */ - public function totalPriceForItemsShouldEqualTo(int $price) + public function totalPriceForItemsShouldEqualTo(int $price): void { $orderTotal = (int) $this->client->getValueAtKey('order.total'); $shippingTotal = (int) $this->client->getValueAtKey('order.shippingTotal'); diff --git a/tests/Behat/Context/Shop/CheckoutContext.php b/src/Behat/Context/Shop/CheckoutContext.php similarity index 95% rename from tests/Behat/Context/Shop/CheckoutContext.php rename to src/Behat/Context/Shop/CheckoutContext.php index ef603494..e8494967 100644 --- a/tests/Behat/Context/Shop/CheckoutContext.php +++ b/src/Behat/Context/Shop/CheckoutContext.php @@ -8,12 +8,12 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Sylius\Behat\Service\SharedStorageInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; final class CheckoutContext implements Context { diff --git a/tests/Behat/Context/Shop/CustomerContext.php b/src/Behat/Context/Shop/CustomerContext.php similarity index 89% rename from tests/Behat/Context/Shop/CustomerContext.php rename to src/Behat/Context/Shop/CustomerContext.php index 1245ca7f..3e819407 100644 --- a/tests/Behat/Context/Shop/CustomerContext.php +++ b/src/Behat/Context/Shop/CustomerContext.php @@ -8,16 +8,16 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use ApiPlatform\Core\Api\IriConverterInterface; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use BitBag\SyliusGraphqlPlugin\Factory\ShopUserTokenFactoryInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Webmozart\Assert\Assert; final class CustomerContext implements Context @@ -103,25 +103,33 @@ public function iCreateJWTTokenForCustomer(string $email): void /** * @When I set IRI of this customer request to match :arg */ - public function iSetIriForThisCustomerRequest(string $email) + public function iSetIriForThisCustomerRequest(string $email): void { $operation = $this->client->getLastOperationRequest(); + Assert::notNull($operation); /** @var ShopUserInterface|null $user */ $user = $this->userRepository->findOneBy(['username' => $email]); - $id = $this->iriConverter->getIriFromItem($user->getCustomer()); + Assert::notNull($user); + $customer = $user->getCustomer(); + Assert::notNull($customer); + + $id = $this->iriConverter->getIriFromItem($customer); $operation->addVariable('id', $id); } /** * @When I set id of this user request to match :arg */ - public function iSetIdForThisUserRequest(string $email) + public function iSetIdForThisUserRequest(string $email): void { $operation = $this->client->getLastOperationRequest(); + Assert::notNull($operation); /** @var ShopUserInterface|null $user */ $user = $this->userRepository->findOneBy(['username' => $email]); + Assert::notNull($user); + $operation->addVariable('shopUserId', (string) $user->getId()); } diff --git a/tests/Behat/Context/Shop/LoginContext.php b/src/Behat/Context/Shop/LoginContext.php similarity index 84% rename from tests/Behat/Context/Shop/LoginContext.php rename to src/Behat/Context/Shop/LoginContext.php index 436255a1..04974c94 100644 --- a/tests/Behat/Context/Shop/LoginContext.php +++ b/src/Behat/Context/Shop/LoginContext.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Sylius\Behat\Service\SharedStorageInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; final class LoginContext implements Context { diff --git a/tests/Behat/Context/Shop/ProductContext.php b/src/Behat/Context/Shop/ProductContext.php similarity index 90% rename from tests/Behat/Context/Shop/ProductContext.php rename to src/Behat/Context/Shop/ProductContext.php index 450559f0..5fb6ed85 100644 --- a/tests/Behat/Context/Shop/ProductContext.php +++ b/src/Behat/Context/Shop/ProductContext.php @@ -8,15 +8,15 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use ApiPlatform\Core\Api\IriConverterInterface; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; +use BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; final class ProductContext implements Context { diff --git a/tests/Behat/Context/Shop/RegistrationContext.php b/src/Behat/Context/Shop/RegistrationContext.php similarity index 92% rename from tests/Behat/Context/Shop/RegistrationContext.php rename to src/Behat/Context/Shop/RegistrationContext.php index 588cc7dc..a68bb033 100644 --- a/tests/Behat/Context/Shop/RegistrationContext.php +++ b/src/Behat/Context/Shop/RegistrationContext.php @@ -8,13 +8,13 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; +namespace BitBag\SyliusGraphqlPlugin\Behat\Context\Shop; use Behat\Behat\Context\Context; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; +use BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; use Sylius\Behat\Service\SharedStorageInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClient; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Model\OperationRequestInterface; final class RegistrationContext implements Context { diff --git a/src/Behat/Context/Shop/TaxonContext.php b/src/Behat/Context/Shop/TaxonContext.php new file mode 100644 index 00000000..e07b6c1f --- /dev/null +++ b/src/Behat/Context/Shop/TaxonContext.php @@ -0,0 +1,70 @@ +client = $client; + $this->sharedStorage = $sharedStorage; + } + + /** + * @When I prepare query to fetch all taxa + */ + public function iPrepareFetchTaxaQuery(): void + { + $expectedData = ' + collection { + root{ + id + slug + } + id + _id + name + fullname + slug + code + enabled + position + description + left + right + level + createdAt + updatedAt + translations{ + collection{ + slug + name + locale + } + }'; + + $operation = $this->client->prepareQuery('taxa', $expectedData); + $operation->setOperationType(OperationRequestInterface::OPERATION_QUERY); + $this->sharedStorage->set(GraphqlClient::GRAPHQL_OPERATION, $operation); + } +} diff --git a/tests/Behat/Model/OperationRequest.php b/src/Behat/Model/OperationRequest.php similarity index 98% rename from tests/Behat/Model/OperationRequest.php rename to src/Behat/Model/OperationRequest.php index 5df89a75..5c374392 100644 --- a/tests/Behat/Model/OperationRequest.php +++ b/src/Behat/Model/OperationRequest.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Model; +namespace BitBag\SyliusGraphqlPlugin\Behat\Model; use Symfony\Component\HttpFoundation\Request; diff --git a/tests/Behat/Model/OperationRequestInterface.php b/src/Behat/Model/OperationRequestInterface.php similarity index 95% rename from tests/Behat/Model/OperationRequestInterface.php rename to src/Behat/Model/OperationRequestInterface.php index 5f22ac6d..61a1928e 100644 --- a/tests/Behat/Model/OperationRequestInterface.php +++ b/src/Behat/Model/OperationRequestInterface.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Model; +namespace BitBag\SyliusGraphqlPlugin\Behat\Model; use Symfony\Component\HttpFoundation\Request; diff --git a/tests/Behat/Resources/suites.yml b/src/Behat/Resources/suites.yml similarity index 100% rename from tests/Behat/Resources/suites.yml rename to src/Behat/Resources/suites.yml diff --git a/tests/Behat/Resources/suites/account/changing_password.yaml b/src/Behat/Resources/suites/account/changing_password.yaml similarity index 67% rename from tests/Behat/Resources/suites/account/changing_password.yaml rename to src/Behat/Resources/suites/account/changing_password.yaml index 7dccd65a..63125ebe 100755 --- a/tests/Behat/Resources/suites/account/changing_password.yaml +++ b/src/Behat/Resources/suites/account/changing_password.yaml @@ -4,9 +4,9 @@ default: contexts: - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.login + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.login - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.shared_storage filters: diff --git a/tests/Behat/Resources/suites/account/creating_account.yaml b/src/Behat/Resources/suites/account/creating_account.yaml similarity index 61% rename from tests/Behat/Resources/suites/account/creating_account.yaml rename to src/Behat/Resources/suites/account/creating_account.yaml index 99c8d9d9..8fb60259 100755 --- a/tests/Behat/Resources/suites/account/creating_account.yaml +++ b/src/Behat/Resources/suites/account/creating_account.yaml @@ -4,10 +4,10 @@ default: contexts: - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.login - - bitbag_sylius_graphql_plugin.context.registration + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.login + - bitbag.sylius_graphql_plugin.context.registration - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.shared_storage filters: diff --git a/tests/Behat/Resources/suites/account/editing_account.yaml b/src/Behat/Resources/suites/account/editing_account.yaml similarity index 63% rename from tests/Behat/Resources/suites/account/editing_account.yaml rename to src/Behat/Resources/suites/account/editing_account.yaml index 2d5ab290..bca296e3 100755 --- a/tests/Behat/Resources/suites/account/editing_account.yaml +++ b/src/Behat/Resources/suites/account/editing_account.yaml @@ -4,10 +4,10 @@ default: contexts: - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.login - - bitbag_sylius_graphql_plugin.context.registration + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.login + - bitbag.sylius_graphql_plugin.context.registration - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.shared_storage - sylius.behat.context.transform.lexical diff --git a/tests/Behat/Resources/suites/account/managing_addresses.yaml b/src/Behat/Resources/suites/account/managing_addresses.yaml similarity index 60% rename from tests/Behat/Resources/suites/account/managing_addresses.yaml rename to src/Behat/Resources/suites/account/managing_addresses.yaml index 3eb52147..1c9c1a5f 100755 --- a/tests/Behat/Resources/suites/account/managing_addresses.yaml +++ b/src/Behat/Resources/suites/account/managing_addresses.yaml @@ -4,10 +4,10 @@ default: contexts: - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.login - - bitbag_sylius_graphql_plugin.context.address + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.login + - bitbag.sylius_graphql_plugin.context.address - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.shared_storage filters: diff --git a/tests/Behat/Resources/suites/cart/place_order_as_customer.yaml b/src/Behat/Resources/suites/cart/place_order_as_customer.yaml similarity index 60% rename from tests/Behat/Resources/suites/cart/place_order_as_customer.yaml rename to src/Behat/Resources/suites/cart/place_order_as_customer.yaml index 7d1d66c6..0f88c3b7 100755 --- a/tests/Behat/Resources/suites/cart/place_order_as_customer.yaml +++ b/src/Behat/Resources/suites/cart/place_order_as_customer.yaml @@ -2,13 +2,13 @@ default: suites: graphql_place_order_customer: contexts: - - bitbag_sylius_graphql_plugin.context.address - - bitbag_sylius_graphql_plugin.context.cart - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.login - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.checkout - - bitbag_sylius_graphql_plugin.context.product + - bitbag.sylius_graphql_plugin.context.address + - bitbag.sylius_graphql_plugin.context.cart + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.login + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.checkout + - bitbag.sylius_graphql_plugin.context.product - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer diff --git a/tests/Behat/Resources/suites/cart/place_order_as_guest.yaml b/src/Behat/Resources/suites/cart/place_order_as_guest.yaml similarity index 63% rename from tests/Behat/Resources/suites/cart/place_order_as_guest.yaml rename to src/Behat/Resources/suites/cart/place_order_as_guest.yaml index 029b2f5a..a020d82e 100755 --- a/tests/Behat/Resources/suites/cart/place_order_as_guest.yaml +++ b/src/Behat/Resources/suites/cart/place_order_as_guest.yaml @@ -2,12 +2,12 @@ default: suites: graphql_place_order_guest: contexts: - - bitbag_sylius_graphql_plugin.context.address - - bitbag_sylius_graphql_plugin.context.cart - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.checkout - - bitbag_sylius_graphql_plugin.context.product + - bitbag.sylius_graphql_plugin.context.address + - bitbag.sylius_graphql_plugin.context.cart + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.checkout + - bitbag.sylius_graphql_plugin.context.product - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer diff --git a/tests/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml b/src/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml similarity index 60% rename from tests/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml rename to src/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml index abb44890..998094a3 100755 --- a/tests/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml +++ b/src/Behat/Resources/suites/cart/place_order_as_guest_customer.yaml @@ -2,13 +2,13 @@ default: suites: graphql_place_order_guest_customer: contexts: - - bitbag_sylius_graphql_plugin.context.address - - bitbag_sylius_graphql_plugin.context.cart - - bitbag_sylius_graphql_plugin.context.customer - - bitbag_sylius_graphql_plugin.context.login - - bitbag_sylius_graphql_plugin.context.graphql - - bitbag_sylius_graphql_plugin.context.checkout - - bitbag_sylius_graphql_plugin.context.product + - bitbag.sylius_graphql_plugin.context.address + - bitbag.sylius_graphql_plugin.context.cart + - bitbag.sylius_graphql_plugin.context.customer + - bitbag.sylius_graphql_plugin.context.login + - bitbag.sylius_graphql_plugin.context.graphql + - bitbag.sylius_graphql_plugin.context.checkout + - bitbag.sylius_graphql_plugin.context.product - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer diff --git a/tests/Behat/Service/ApiSecurityService.php b/src/Behat/Service/ApiSecurityService.php similarity index 84% rename from tests/Behat/Service/ApiSecurityService.php rename to src/Behat/Service/ApiSecurityService.php index 7ac849cf..6f8f7edd 100644 --- a/tests/Behat/Service/ApiSecurityService.php +++ b/src/Behat/Service/ApiSecurityService.php @@ -8,14 +8,15 @@ declare(strict_types=1); -namespace Tests\BitBag\SyliusGraphqlPlugin\Behat\Service; +namespace BitBag\SyliusGraphqlPlugin\Behat\Service; +use BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; use Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Token\JWTUserToken; use Sylius\Behat\Service\SecurityServiceInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\User\Model\UserInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Tests\BitBag\SyliusGraphqlPlugin\Behat\Client\GraphqlClientInterface; +use Webmozart\Assert\Assert; final class ApiSecurityService implements SecurityServiceInterface { @@ -46,7 +47,9 @@ public function logOut(): void public function getCurrentToken(): TokenInterface { $token = new JWTUserToken(); - $token->setRawToken($this->sharedStorage->get('token')); + $storageToken = $this->sharedStorage->get('token'); + Assert::string($storageToken); + $token->setRawToken($storageToken); return $token; } diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 43bfa98f..37904ba2 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -10,7 +10,7 @@ We are hiring developers from all over the world. Join us and start your new, ex xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + diff --git a/tests/Behat/Resources/services/clients.xml b/src/Resources/services/behat/clients.xml similarity index 79% rename from tests/Behat/Resources/services/clients.xml rename to src/Resources/services/behat/clients.xml index d8e8cf4d..365e2ed4 100755 --- a/tests/Behat/Resources/services/clients.xml +++ b/src/Resources/services/behat/clients.xml @@ -5,8 +5,8 @@ - + Bearer diff --git a/src/Resources/services/behat/contexts.xml b/src/Resources/services/behat/contexts.xml new file mode 100755 index 00000000..29dc746d --- /dev/null +++ b/src/Resources/services/behat/contexts.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml deleted file mode 100644 index 93db27fb..00000000 --- a/tests/Behat/Resources/services.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - diff --git a/tests/Behat/Resources/services/contexts.xml b/tests/Behat/Resources/services/contexts.xml deleted file mode 100755 index 782739fc..00000000 --- a/tests/Behat/Resources/services/contexts.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -