diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Adjustment.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Adjustment.xml index 9395474f348..4f0a054af78 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Adjustment.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Adjustment.xml @@ -45,7 +45,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -154,7 +154,7 @@ - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AdminUserPassword.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AdminUserPassword.xml index edb8cbf291d..d071ac24a2c 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AdminUserPassword.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AdminUserPassword.xml @@ -60,7 +60,7 @@ class="ApiPlatform\Metadata\Patch" uriTemplate="/admin/administrators/reset-password/{token}" input="Sylius\Bundle\CoreBundle\Message\Admin\Account\ResetPassword" - provider="Sylius\Bundle\ApiBundle\StateProvider\Admin\ResetPasswordProvider" + provider="sylius_api.state_provider.admin.admin_user.reset_password" > diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Channel.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Channel.xml index fa2a273d3c1..7eba3a68f5a 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Channel.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Channel.xml @@ -64,7 +64,7 @@ - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Command/VerifyShopUser.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Command/VerifyShopUser.xml index 202b9ce2b4e..26c5985cc0c 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Command/VerifyShopUser.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Command/VerifyShopUser.xml @@ -61,7 +61,7 @@ class="ApiPlatform\Metadata\Patch" uriTemplate="/shop/customers/verify/{token}" input="Sylius\Bundle\ApiBundle\Command\Account\VerifyShopUser" - provider="Sylius\Bundle\ApiBundle\StateProvider\Input\VerifyShopUserStateProvider" + provider="sylius_api.state_provider.shop.shop_user.verify_shop_user" > diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ProductAttributeValue.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ProductAttributeValue.xml index dab05186f3d..f5060f6d671 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ProductAttributeValue.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ProductAttributeValue.xml @@ -67,7 +67,7 @@ - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ShopUserResetPassword.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ShopUserResetPassword.xml index 1878516e813..e3236b4f8c8 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ShopUserResetPassword.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/ShopUserResetPassword.xml @@ -19,7 +19,6 @@ @@ -62,6 +61,7 @@ output="false" status="202" uriTemplate="/shop/customers/reset-password/{token}" + provider="sylius_api.state_provider.shop.shop_user.reset_password" > diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_providers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_providers.xml index 9e213ab5972..922d7c9f8bd 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_providers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_providers.xml @@ -16,47 +16,59 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - + tokenValue - + + + + + + tokenValue + - + + id - + - + - + + - - + + + - + + - + + - + - + + %locale% - + diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Admin/AdminUser/ResetPasswordProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Admin/AdminUser/ResetPasswordProvider.php new file mode 100644 index 00000000000..3ed94a6fdb0 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Admin/AdminUser/ResetPasswordProvider.php @@ -0,0 +1,40 @@ + */ +final readonly class ResetPasswordProvider implements ProviderInterface +{ + public function __construct(private SectionProviderInterface $sectionProvider) + { + } + + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ResetPassword + { + Assert::true(is_a($operation->getClass(), ResetPassword::class, true)); + Assert::isInstanceOf($operation, Patch::class); + Assert::isInstanceOf($this->sectionProvider->getSection(), AdminApiSection::class); + Assert::stringNotEmpty($uriVariables['token'] ?? null, 'Token is required.'); + + return new ResetPassword($uriVariables['token']); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Admin/ResetPasswordProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Admin/ResetPasswordProvider.php deleted file mode 100644 index d3dfc7bb58e..00000000000 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/Admin/ResetPasswordProvider.php +++ /dev/null @@ -1,35 +0,0 @@ -getClass(), ResetPassword::class, true)); - - if ($operation instanceof Patch) { - return new ResetPassword($uriVariables['token']); - } - - throw new \RuntimeException('Only PATCH operation is supported.'); - } -} diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/RecursiveAdjustmentsProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Common/Adjustment/CollectionProvider.php similarity index 77% rename from src/Sylius/Bundle/ApiBundle/StateProvider/RecursiveAdjustmentsProvider.php rename to src/Sylius/Bundle/ApiBundle/StateProvider/Common/Adjustment/CollectionProvider.php index 948269021d7..2ea3262faa6 100644 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/RecursiveAdjustmentsProvider.php +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Common/Adjustment/CollectionProvider.php @@ -11,16 +11,19 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\StateProvider; +namespace Sylius\Bundle\ApiBundle\StateProvider\Common\Adjustment; +use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use Doctrine\Common\Collections\Collection; use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Order\Model\RecursiveAdjustmentsAwareInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; +use Webmozart\Assert\Assert; -final readonly class RecursiveAdjustmentsProvider implements ProviderInterface +/** @implements ProviderInterface */ +final readonly class CollectionProvider implements ProviderInterface { public function __construct( private RepositoryInterface $repository, @@ -37,10 +40,10 @@ public function __construct( /** @return Collection */ public function provide(Operation $operation, array $uriVariables = [], array $context = []): Collection { + Assert::true(is_a($operation->getClass(), AdjustmentInterface::class, true)); + Assert::isInstanceOf($operation, GetCollection::class); $identifier = $uriVariables[$this->identifier] ?? null; - if (null === $identifier) { - throw new \RuntimeException('No identifier provided in `uri_variables`.'); - } + Assert::notNull($identifier, 'No identifier provided in `uri_variables`.'); /** @var RecursiveAdjustmentsAwareInterface|null $adjustable */ $adjustable = $this->repository->findOneBy([$this->identifier => $identifier]); diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Channel/CollectionProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Channel/CollectionProvider.php new file mode 100644 index 00000000000..079eda90a64 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Channel/CollectionProvider.php @@ -0,0 +1,41 @@ + */ +final readonly class CollectionProvider implements ProviderInterface +{ + public function __construct(private SectionProviderInterface $sectionProvider) + { + } + + public function provide(Operation $operation, array $uriVariables = [], array $context = []): array + { + Assert::true(is_a($operation->getClass(), ChannelInterface::class, true)); + Assert::isInstanceOf($operation, GetCollection::class); + Assert::isInstanceOf($this->sectionProvider->getSection(), ShopApiSection::class); + Assert::keyExists($context, ContextKeys::CHANNEL); + + return [$context[ContextKeys::CHANNEL]]; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ChannelProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ChannelProvider.php deleted file mode 100644 index 007af74b04a..00000000000 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ChannelProvider.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -final readonly class ChannelProvider implements ProviderInterface -{ - public function __construct(private readonly SectionProviderInterface $sectionProvider) - { - } - - /** - * @throws \Exception - */ - public function provide(Operation $operation, array $uriVariables = [], array $context = []): array - { - Assert::same($operation->getClass(), Channel::class); - - if ($this->isShopGetCollectionOperation($operation) && isset($context['sylius_api_channel'])) { - return [$context['sylius_api_channel']]; - } - - throw new \RuntimeException('Only Shop GET collection operation is supported.'); - } - - private function isShopGetCollectionOperation(Operation $operation): bool - { - return $operation instanceof GetCollection && $this->sectionProvider->getSection() instanceof ShopApiSection; - } -} diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/OrderItemAdjustmentsProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Order/OrderItem/Adjustment/CollectionProvider.php similarity index 59% rename from src/Sylius/Bundle/ApiBundle/StateProvider/Shop/OrderItemAdjustmentsProvider.php rename to src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Order/OrderItem/Adjustment/CollectionProvider.php index ffc2efb4eed..6e67596cb97 100644 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/OrderItemAdjustmentsProvider.php +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Order/OrderItem/Adjustment/CollectionProvider.php @@ -11,22 +11,33 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\StateProvider\Shop; +namespace Sylius\Bundle\ApiBundle\StateProvider\Shop\Order\OrderItem\Adjustment; +use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use Doctrine\Common\Collections\Collection; +use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection; +use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Repository\OrderItemRepositoryInterface; +use Webmozart\Assert\Assert; -final readonly class OrderItemAdjustmentsProvider implements ProviderInterface +/** @implements ProviderInterface */ +final readonly class CollectionProvider implements ProviderInterface { public function __construct( private OrderItemRepositoryInterface $orderItemRepository, + private SectionProviderInterface $sectionProvider, ) { } public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|Collection { + Assert::true(is_a($operation->getClass(), AdjustmentInterface::class, true)); + Assert::isInstanceOf($operation, GetCollection::class); + Assert::isInstanceOf($this->sectionProvider->getSection(), ShopApiSection::class); + if (false === isset($uriVariables['id'], $uriVariables['tokenValue'])) { return []; } diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/ProductAttributesProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Product/ProductAttributeValue/CollectionProvider.php similarity index 72% rename from src/Sylius/Bundle/ApiBundle/StateProvider/ProductAttributesProvider.php rename to src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Product/ProductAttributeValue/CollectionProvider.php index 5673525c9b1..a755b07f077 100644 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/ProductAttributesProvider.php +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/Product/ProductAttributeValue/CollectionProvider.php @@ -11,22 +11,27 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\StateProvider; +namespace Sylius\Bundle\ApiBundle\StateProvider\Shop\Product\ProductAttributeValue; use ApiPlatform\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; +use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; +use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection; +use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; use Sylius\Component\Locale\Provider\LocaleProviderInterface; -use Sylius\Component\Product\Model\ProductAttributeValue; +use Sylius\Component\Product\Model\ProductAttributeValueInterface; use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface; +use Webmozart\Assert\Assert; -/** @implements ProviderInterface */ -final class ProductAttributesProvider implements ProviderInterface +/** @implements ProviderInterface */ +final readonly class CollectionProvider implements ProviderInterface { public function __construct( private iterable $collectionExtensions, + private SectionProviderInterface $sectionProvider, private ProductAttributeValueRepositoryInterface $attributeValueRepository, private LocaleContextInterface $localeContext, private LocaleProviderInterface $localeProvider, @@ -36,6 +41,10 @@ public function __construct( public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|object|null { + Assert::true(is_a($operation->getClass(), ProductAttributeValueInterface::class, true)); + Assert::isInstanceOf($operation, GetCollection::class); + Assert::isInstanceOf($this->sectionProvider->getSection(), ShopApiSection::class); + $queryBuilder = $this->attributeValueRepository->createByProductCodeAndLocaleQueryBuilder( $uriVariables['code'], $this->localeContext->getLocaleCode(), diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ShopUser/ResetPasswordProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ShopUser/ResetPasswordProvider.php new file mode 100644 index 00000000000..fef9e7c16ba --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ShopUser/ResetPasswordProvider.php @@ -0,0 +1,40 @@ + */ +final readonly class ResetPasswordProvider implements ProviderInterface +{ + public function __construct(private SectionProviderInterface $sectionProvider) + { + } + + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ResetPassword + { + Assert::true(is_a($operation->getClass(), ResetPassword::class, true)); + Assert::isInstanceOf($operation, Patch::class); + Assert::isInstanceOf($this->sectionProvider->getSection(), ShopApiSection::class); + Assert::stringNotEmpty($uriVariables['token'] ?? null, 'Token is required.'); + + return new ResetPassword($uriVariables['token']); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/Input/VerifyShopUserStateProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ShopUser/VerifyShopUserProvider.php similarity index 50% rename from src/Sylius/Bundle/ApiBundle/StateProvider/Input/VerifyShopUserStateProvider.php rename to src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ShopUser/VerifyShopUserProvider.php index c5e815332ab..e16492c2e4a 100644 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/Input/VerifyShopUserStateProvider.php +++ b/src/Sylius/Bundle/ApiBundle/StateProvider/Shop/ShopUser/VerifyShopUserProvider.php @@ -11,29 +11,31 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\StateProvider\Input; +namespace Sylius\Bundle\ApiBundle\StateProvider\Shop\ShopUser; use ApiPlatform\Metadata\Operation; +use ApiPlatform\Metadata\Patch; use ApiPlatform\State\ProviderInterface; use Sylius\Bundle\ApiBundle\Command\Account\VerifyShopUser; +use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection; use Sylius\Bundle\ApiBundle\Serializer\ContextKeys; +use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface; use Webmozart\Assert\Assert; -/** - * @experimental - * - * @implements ProviderInterface - */ -final class VerifyShopUserStateProvider implements ProviderInterface +/** @implements ProviderInterface */ +final readonly class VerifyShopUserProvider implements ProviderInterface { - public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|object|null + public function __construct(private SectionProviderInterface $sectionProvider) { - if (!is_a($operation->getClass(), VerifyShopUser::class, true)) { - return null; - } + } + public function provide(Operation $operation, array $uriVariables = [], array $context = []): VerifyShopUser + { + Assert::true(is_a($operation->getClass(), VerifyShopUser::class, true)); + Assert::isInstanceOf($operation, Patch::class); + Assert::isInstanceOf($this->sectionProvider->getSection(), ShopApiSection::class); Assert::stringNotEmpty($uriVariables['token'] ?? null, 'Token is required.'); - return new VerifyShopUser($uriVariables['token'], $context[ContextKeys::CHANNEL]->getCode(), $context[ContextKeys::LOCALE_CODE], ); + return new VerifyShopUser($uriVariables['token'], $context[ContextKeys::CHANNEL]->getCode(), $context[ContextKeys::LOCALE_CODE]); } } diff --git a/src/Sylius/Bundle/ApiBundle/StateProvider/ShopUserResetPasswordProvider.php b/src/Sylius/Bundle/ApiBundle/StateProvider/ShopUserResetPasswordProvider.php deleted file mode 100644 index a799f9d281e..00000000000 --- a/src/Sylius/Bundle/ApiBundle/StateProvider/ShopUserResetPasswordProvider.php +++ /dev/null @@ -1,42 +0,0 @@ - - */ -final readonly class ShopUserResetPasswordProvider implements ProviderInterface -{ - /** - * @throws \Exception - */ - public function provide(Operation $operation, array $uriVariables = [], array $context = []): ResetPassword - { - Assert::same($operation->getClass(), ResetPassword::class); - - if ($operation instanceof Patch) { - return new ResetPassword($uriVariables['token']); - } - - throw new \RuntimeException('Only PATCH operation is supported.'); - } -} diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Admin/AdminUser/ResetPasswordProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Admin/AdminUser/ResetPasswordProviderSpec.php new file mode 100644 index 00000000000..66a59261d70 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Admin/AdminUser/ResetPasswordProviderSpec.php @@ -0,0 +1,95 @@ +beConstructedWith($sectionProvider); + } + + function it_provides_reset_password_class( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: ResetPassword::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this + ->provide($operation, ['token' => 'resetToken']) + ->shouldBeLike(new ResetPassword('resetToken')) + ; + } + + function it_throws_an_exception_when_operation_class_is_not_reset_password( + Operation $operation, + ): void { + $operation->getClass()->willReturn(\stdClass::class); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_patch( + Operation $operation, + SectionProviderInterface $sectionProvider, + ): void { + $operation->getClass()->willReturn(ResetPassword::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_in_shop_api_section( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: ResetPassword::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_invalid_argument_exception_when_no_token_is_provided( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: ResetPassword::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, ['token' => null]]) + ; + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, ['token' => '']]) + ; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Admin/ResetPasswordProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Admin/ResetPasswordProviderSpec.php deleted file mode 100644 index 6816693ec5b..00000000000 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Admin/ResetPasswordProviderSpec.php +++ /dev/null @@ -1,48 +0,0 @@ -provide($operation, ['token' => 'resetToken']) - ->shouldBeLike(new ResetPassword('resetToken')) - ; - } - - function it_throws_an_exception_when_operation_is_not_patch(Operation $operation): void - { - $operation->getClass()->willReturn(ResetPassword::class); - - $this->shouldThrow(\RuntimeException::class) - ->during('provide', [$operation]) - ; - } - - function it_provides_nothing_if_operation_is_not_reset_password(): void - { - $operation = new Patch(class: 'NotResetPassword'); - - $this->shouldThrow(\InvalidArgumentException::class)->during('provide', [$operation]); - } -} diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/RecursiveAdjustmentsProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Common/Adjustment/CollectionProviderSpec.php similarity index 85% rename from src/Sylius/Bundle/ApiBundle/spec/StateProvider/RecursiveAdjustmentsProviderSpec.php rename to src/Sylius/Bundle/ApiBundle/spec/StateProvider/Common/Adjustment/CollectionProviderSpec.php index 53394e7799c..171588f2f38 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/RecursiveAdjustmentsProviderSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Common/Adjustment/CollectionProviderSpec.php @@ -11,8 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ApiBundle\StateProvider; +namespace spec\Sylius\Bundle\ApiBundle\StateProvider\Common\Adjustment; +use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use Doctrine\Common\Collections\ArrayCollection; @@ -23,7 +24,7 @@ use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\HttpFoundation\Request; -final class RecursiveAdjustmentsProviderSpec extends ObjectBehavior +final class CollectionProviderSpec extends ObjectBehavior { private const IDENTIFIER = 'id'; @@ -49,20 +50,20 @@ function it_throws_logic_exception_when_repository_is_not_for_a_recursive_adjust function it_throws_exception_when_identifier_is_missing_from_uri_variables( RepositoryInterface $repository, - Operation $operation, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); $repository->findOneBy(Argument::any())->shouldNotBeCalled(); $this - ->shouldThrow(\RuntimeException::class) + ->shouldThrow(\InvalidArgumentException::class) ->during('provide', [$operation, []]) ; } function it_throws_exception_when_resource_cannot_be_found( RepositoryInterface $repository, - Operation $operation, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); $repository->findOneBy([self::IDENTIFIER => 1])->willReturn(null); $this @@ -75,11 +76,11 @@ function it_returns_adjustments_recursively( RepositoryInterface $repository, Request $request, Request $queryRequest, - Operation $operation, OrderItem $orderItem, AdjustmentInterface $firstAdjustment, AdjustmentInterface $secondAdjustment, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); $request->query = $queryRequest; $queryRequest->get('type')->willReturn('type'); $adjustments = new ArrayCollection([ diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Input/VerifyShopUserStateProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Input/VerifyShopUserStateProviderSpec.php deleted file mode 100644 index e71b8c3e76e..00000000000 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Input/VerifyShopUserStateProviderSpec.php +++ /dev/null @@ -1,61 +0,0 @@ -getClass()->willReturn(\stdClass::class); - - $this->provide($operation)->shouldReturn(null); - } - - function it_throws_invalid_argument_exception_when_no_token_is_provided(Operation $operation): void - { - $operation->getClass()->willReturn(VerifyShopUser::class); - - $this - ->shouldThrow(\InvalidArgumentException::class) - ->during('provide', [$operation]) - ; - $this - ->shouldThrow(\InvalidArgumentException::class) - ->during('provide', [$operation, ['token' => null]]) - ; - $this - ->shouldThrow(\InvalidArgumentException::class) - ->during('provide', [$operation, ['token' => '']]) - ; - } - - function it_returns_verify_customer_account_command_when_token_is_provided( - ChannelInterface $channel, - Operation $operation, - ): void { - $operation->getClass()->willReturn(VerifyShopUser::class); - $channel->getCode()->willReturn('WEB'); - - $this - ->provide($operation, ['token' => 'TOKEN'], [ContextKeys::CHANNEL => $channel, ContextKeys::LOCALE_CODE => 'en_US']) - ->shouldBeLike(new VerifyShopUser('TOKEN', 'WEB', 'en_US')) - ; - } -} diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ChannelProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Channel/CollectionProviderSpec.php similarity index 53% rename from src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ChannelProviderSpec.php rename to src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Channel/CollectionProviderSpec.php index 9db2d930b64..93dc3b37af3 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ChannelProviderSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Channel/CollectionProviderSpec.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ApiBundle\StateProvider\Shop; +namespace spec\Sylius\Bundle\ApiBundle\StateProvider\Shop\Channel; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; @@ -22,15 +22,17 @@ use Sylius\Component\Core\Model\Channel; use Sylius\Component\Core\Model\ChannelInterface; -final class ChannelProviderSpec extends ObjectBehavior +final class CollectionProviderSpec extends ObjectBehavior { function let(SectionProviderInterface $sectionProvider): void { $this->beConstructedWith($sectionProvider); } - function it_provides_channel(ChannelInterface $channel, SectionProviderInterface $sectionProvider): void - { + function it_provides_channel( + ChannelInterface $channel, + SectionProviderInterface $sectionProvider, + ): void { $operation = new GetCollection(class: Channel::class); $sectionProvider->getSection()->willReturn(new ShopApiSection()); @@ -40,23 +42,48 @@ function it_provides_channel(ChannelInterface $channel, SectionProviderInterface ; } - function it_throws_an_exception_when_operation_is_not_get_collection(Operation $operation, SectionProviderInterface $sectionProvider): void - { + function it_throws_an_exception_when_operation_class_is_not_channel( + Operation $operation, + ): void { + $operation->getClass()->willReturn(\stdClass::class); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_get_collection( + Operation $operation, + SectionProviderInterface $sectionProvider, + ): void { $operation->getClass()->willReturn(Channel::class); $sectionProvider->getSection()->willReturn(new ShopApiSection()); - $this->shouldThrow(\RuntimeException::class) + $this->shouldThrow(\InvalidArgumentException::class) ->during('provide', [$operation]) ; } - function it_throws_exception_if_operation_is_not_shop(ChannelInterface $channel, SectionProviderInterface $sectionProvider): void - { + function it_throws_an_exception_when_operation_is_not_in_shop_api_section( + ChannelInterface $channel, + SectionProviderInterface $sectionProvider, + ): void { $operation = new GetCollection(class: Channel::class); $sectionProvider->getSection()->willReturn(new AdminApiSection()); - $this->shouldThrow(\RuntimeException::class) + $this->shouldThrow(\InvalidArgumentException::class) ->during('provide', [$operation, [], ['sylius_api_channel' => $channel]]) ; } + + function it_throws_an_exception_when_context_does_not_have_channel( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new GetCollection(class: Channel::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, [], []]) + ; + } } diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/OrderItemAdjustmentsProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Order/OrderItem/Adjustment/CollectionProviderSpec.php similarity index 51% rename from src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/OrderItemAdjustmentsProviderSpec.php rename to src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Order/OrderItem/Adjustment/CollectionProviderSpec.php index b5def2be3d3..22199a6490f 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/OrderItemAdjustmentsProviderSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Order/OrderItem/Adjustment/CollectionProviderSpec.php @@ -11,23 +11,29 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ApiBundle\StateProvider\Shop; +namespace spec\Sylius\Bundle\ApiBundle\StateProvider\Shop\Order\OrderItem\Adjustment; +use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use Doctrine\Common\Collections\ArrayCollection; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Sylius\Bundle\ApiBundle\SectionResolver\AdminApiSection; +use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection; +use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface; use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderItem; use Sylius\Component\Core\Repository\OrderItemRepositoryInterface; use Symfony\Component\HttpFoundation\Request; -final class OrderItemAdjustmentsProviderSpec extends ObjectBehavior +final class CollectionProviderSpec extends ObjectBehavior { - public function let(OrderItemRepositoryInterface $orderItemRepository): void - { - $this->beConstructedWith($orderItemRepository); + public function let( + OrderItemRepositoryInterface $orderItemRepository, + SectionProviderInterface $sectionProvider, + ): void { + $this->beConstructedWith($orderItemRepository, $sectionProvider); } function it_is_a_state_provider(): void @@ -37,8 +43,10 @@ function it_is_a_state_provider(): void function it_returns_an_empty_array_when_uri_variables_have_no_id( OrderItemRepositoryInterface $orderItemRepository, - Operation $operation, + SectionProviderInterface $sectionProvider, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); $orderItemRepository->findOneByIdAndOrderTokenValue(Argument::cetera())->shouldNotBeCalled(); $this->provide($operation, ['tokenValue' => '42'])->shouldReturn([]); @@ -46,8 +54,10 @@ function it_returns_an_empty_array_when_uri_variables_have_no_id( function it_returns_an_empty_array_when_uri_variables_have_no_token_value( OrderItemRepositoryInterface $orderItemRepository, - Operation $operation, + SectionProviderInterface $sectionProvider, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); $orderItemRepository->findOneByIdAndOrderTokenValue(Argument::cetera())->shouldNotBeCalled(); $this->provide($operation, ['id' => 42])->shouldReturn([]); @@ -55,8 +65,10 @@ function it_returns_an_empty_array_when_uri_variables_have_no_token_value( function it_returns_an_empty_array_when_no_order_item_can_be_found( OrderItemRepositoryInterface $orderItemRepository, - Operation $operation, + SectionProviderInterface $sectionProvider, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); $orderItemRepository->findOneByIdAndOrderTokenValue(42, 'token')->willReturn(null); $this->provide($operation, ['id' => '42', 'tokenValue' => 'token'])->shouldReturn([]); @@ -64,13 +76,16 @@ function it_returns_an_empty_array_when_no_order_item_can_be_found( function it_returns_adjustments_recursively( OrderItemRepositoryInterface $orderItemRepository, + SectionProviderInterface $sectionProvider, Request $request, Request $queryRequest, - Operation $operation, OrderItem $orderItem, AdjustmentInterface $firstAdjustment, AdjustmentInterface $secondAdjustment, ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + $request->query = $queryRequest; $queryRequest->get('type')->willReturn('type'); $adjustments = new ArrayCollection([ @@ -83,4 +98,37 @@ function it_returns_adjustments_recursively( $this->provide($operation, ['id' => '42', 'tokenValue' => 'token'], ['request' => $request])->shouldReturn($adjustments); } + + function it_throws_an_exception_when_operation_class_is_not_adjustment( + Operation $operation, + ): void { + $operation->getClass()->willReturn(\stdClass::class); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_get_collection( + Operation $operation, + SectionProviderInterface $sectionProvider, + ): void { + $operation->getClass()->willReturn(AdjustmentInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_in_shop_api_section( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new GetCollection(class: AdjustmentInterface::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } } diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/ProductAttributesProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Product/ProductAttributeValue/CollectionProviderSpec.php similarity index 61% rename from src/Sylius/Bundle/ApiBundle/spec/StateProvider/ProductAttributesProviderSpec.php rename to src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Product/ProductAttributeValue/CollectionProviderSpec.php index 5862dcddaab..162e6d037f8 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/ProductAttributesProviderSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/Product/ProductAttributeValue/CollectionProviderSpec.php @@ -11,24 +11,29 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ApiBundle\StateProvider; +namespace spec\Sylius\Bundle\ApiBundle\StateProvider\Shop\Product\ProductAttributeValue; use ApiPlatform\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; +use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\QueryBuilder; use PhpSpec\ObjectBehavior; -use Sylius\Bundle\ApiBundle\StateProvider\ProductAttributesProvider; +use Sylius\Bundle\ApiBundle\SectionResolver\AdminApiSection; +use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection; +use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; use Sylius\Component\Locale\Provider\LocaleProviderInterface; use Sylius\Component\Product\Model\ProductAttributeValue; +use Sylius\Component\Product\Model\ProductAttributeValueInterface; use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface; -final class ProductAttributesProviderSpec extends ObjectBehavior +final class CollectionProviderSpec extends ObjectBehavior { public function let( + SectionProviderInterface $sectionProvider, ProductAttributeValueRepositoryInterface $attributeValueRepository, LocaleContextInterface $localeContext, LocaleProviderInterface $localeProvider, @@ -39,6 +44,7 @@ public function let( $this->beConstructedWith( $collectionExtensions, + $sectionProvider, $attributeValueRepository, $localeContext, $localeProvider, @@ -46,11 +52,6 @@ public function let( ); } - public function it_is_initializable() - { - $this->shouldHaveType(ProductAttributesProvider::class); - } - public function it_implements_provider_interface() { $this->shouldImplement(ProviderInterface::class); @@ -58,24 +59,25 @@ public function it_implements_provider_interface() public function it_provides_product_attributes( ProductAttributeValueRepositoryInterface $attributeValueRepository, + SectionProviderInterface $sectionProvider, LocaleContextInterface $localeContext, LocaleProviderInterface $localeProvider, QueryBuilder $queryBuilder, - Operation $operation, QueryResultCollectionExtensionInterface $extension, ) { + $operation = new GetCollection(class: ProductAttributeValueInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + $localeContext->getLocaleCode()->willReturn('en_US'); $localeProvider->getDefaultLocaleCode()->willReturn('en_US'); $attributeValueRepository->createByProductCodeAndLocaleQueryBuilder('PRODUCT_CODE', 'en_US', 'en_US', 'en_US') ->willReturn($queryBuilder); - $operation->getClass()->willReturn(ProductAttributeValue::class); - - $extension->applyToCollection($queryBuilder, new QueryNameGenerator(), ProductAttributeValue::class, $operation, []) + $extension->applyToCollection($queryBuilder, new QueryNameGenerator(), ProductAttributeValueInterface::class, $operation, []) ->shouldBeCalled(); - $extension->supportsResult(ProductAttributeValue::class, $operation) + $extension->supportsResult(ProductAttributeValueInterface::class, $operation) ->willReturn(true); $extension->getResult($queryBuilder) @@ -87,25 +89,26 @@ public function it_provides_product_attributes( public function it_returns_query_result_when_no_extensions_support_result( ProductAttributeValueRepositoryInterface $attributeValueRepository, + SectionProviderInterface $sectionProvider, LocaleContextInterface $localeContext, LocaleProviderInterface $localeProvider, QueryBuilder $queryBuilder, AbstractQuery $query, - Operation $operation, QueryResultCollectionExtensionInterface $extension, ) { + $operation = new GetCollection(class: ProductAttributeValueInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + $localeContext->getLocaleCode()->willReturn('en_US'); $localeProvider->getDefaultLocaleCode()->willReturn('en_US'); $attributeValueRepository->createByProductCodeAndLocaleQueryBuilder('PRODUCT_CODE', 'en_US', 'en_US', 'en_US') ->willReturn($queryBuilder); - $operation->getClass()->willReturn(ProductAttributeValue::class); - - $extension->applyToCollection($queryBuilder, new QueryNameGenerator(), ProductAttributeValue::class, $operation, []) + $extension->applyToCollection($queryBuilder, new QueryNameGenerator(), ProductAttributeValueInterface::class, $operation, []) ->shouldBeCalled(); - $extension->supportsResult(ProductAttributeValue::class, $operation) + $extension->supportsResult(ProductAttributeValueInterface::class, $operation) ->willReturn(false); $queryBuilder->getQuery()->willReturn($query); @@ -114,4 +117,37 @@ public function it_returns_query_result_when_no_extensions_support_result( $this->provide($operation, ['code' => 'PRODUCT_CODE'], []) ->shouldReturn([$productAttributeValue]); } + + function it_throws_an_exception_when_operation_class_is_not_product_attribute_value( + Operation $operation, + ): void { + $operation->getClass()->willReturn(\stdClass::class); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_get_collection( + Operation $operation, + SectionProviderInterface $sectionProvider, + ): void { + $operation->getClass()->willReturn(ProductAttributeValueInterface::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_in_shop_api_section( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new GetCollection(class: ProductAttributeValueInterface::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } } diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ShopUser/ResetPasswordProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ShopUser/ResetPasswordProviderSpec.php new file mode 100644 index 00000000000..7f26c5922ff --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ShopUser/ResetPasswordProviderSpec.php @@ -0,0 +1,95 @@ +beConstructedWith($sectionProvider); + } + + function it_provides_reset_password_object_if_operation_is_patch( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: ResetPassword::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + $uriVariables = ['token' => 'TOKEN']; + + $this + ->provide($operation, $uriVariables) + ->shouldBeLike(new ResetPassword('TOKEN')); + } + + function it_throws_an_exception_when_operation_class_is_not_reset_password( + Operation $operation, + ): void { + $operation->getClass()->willReturn(\stdClass::class); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_patch( + Operation $operation, + SectionProviderInterface $sectionProvider, + ): void { + $operation->getClass()->willReturn(ResetPassword::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_in_shop_api_section( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: ResetPassword::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_invalid_argument_exception_when_no_token_is_provided( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: ResetPassword::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, ['token' => null]]) + ; + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, ['token' => '']]) + ; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ShopUser/VerifyShopUserProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ShopUser/VerifyShopUserProviderSpec.php new file mode 100644 index 00000000000..ce3926d8d6f --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/Shop/ShopUser/VerifyShopUserProviderSpec.php @@ -0,0 +1,99 @@ +beConstructedWith($sectionProvider); + } + + function it_returns_verify_customer_account_command_when_token_is_provided( + ChannelInterface $channel, + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: VerifyShopUser::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + $channel->getCode()->willReturn('WEB'); + + $this + ->provide($operation, ['token' => 'TOKEN'], [ContextKeys::CHANNEL => $channel, ContextKeys::LOCALE_CODE => 'en_US']) + ->shouldBeLike(new VerifyShopUser('TOKEN', 'WEB', 'en_US')) + ; + } + + function it_throws_an_exception_when_operation_class_is_not_verify_shop_user( + Operation $operation, + ): void { + $operation->getClass()->willReturn(\stdClass::class); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_patch( + Operation $operation, + SectionProviderInterface $sectionProvider, + ): void { + $operation->getClass()->willReturn(VerifyShopUser::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_an_exception_when_operation_is_not_in_shop_api_section( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: VerifyShopUser::class); + $sectionProvider->getSection()->willReturn(new AdminApiSection()); + + $this->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + } + + function it_throws_invalid_argument_exception_when_no_token_is_provided( + SectionProviderInterface $sectionProvider, + ): void { + $operation = new Patch(class: VerifyShopUser::class); + $sectionProvider->getSection()->willReturn(new ShopApiSection()); + + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation]) + ; + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, ['token' => null]]) + ; + $this + ->shouldThrow(\InvalidArgumentException::class) + ->during('provide', [$operation, ['token' => '']]) + ; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/ShopUserResetPasswordProviderSpec.php b/src/Sylius/Bundle/ApiBundle/spec/StateProvider/ShopUserResetPasswordProviderSpec.php deleted file mode 100644 index 3510b709ffc..00000000000 --- a/src/Sylius/Bundle/ApiBundle/spec/StateProvider/ShopUserResetPasswordProviderSpec.php +++ /dev/null @@ -1,53 +0,0 @@ -getClass()->willReturn('NotResetPasswordClass'); - $this - ->shouldThrow(\InvalidArgumentException::class) - ->during('provide', [$operation, [], []]) - ; - } - - function it_provides_reset_password_object_if_operation_is_patch(): void - { - $operation = new Patch(class: ResetPassword::class); - $uriVariables = ['token' => 'TOKEN']; - - $this - ->provide($operation, $uriVariables) - ->shouldBeLike(new ResetPassword('TOKEN')); - } - - function it_throws_an_exception_if_operation_is_different_than_patch(): void - { - $operation = new Get(class: ResetPassword::class); - $uriVariables = ['token' => 'TOKEN']; - - $this - ->shouldThrow(\RuntimeException::class) - ->during('provide', [$operation, $uriVariables]) - ; - } -}