diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1399e3e63..1d41c7956 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: tests: runs-on: ubuntu-20.04 - name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}" + name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}" strategy: fail-fast: false @@ -21,11 +21,16 @@ jobs: php: [7.4, 7.3] node: [10.x] mysql: [5.7, 8.0] + symfony: [^4.4, ^5.2] + sylius: [~1.8.0, ~1.9.0] exclude: - # PHP 7.3 does not support "caching_sha2_password" authentication plugin which is a default one in MySQL 8.0 php: 7.3 mysql: 8.0 + - + sylius: ~1.8.0 + symfony: ^5.2 env: APP_ENV: test @@ -66,6 +71,18 @@ jobs: name: Output PHP version for Symfony CLI run: php -v | head -n 1 | awk '{ print $2 }' > .php-version + - + name: Restrict Symfony version + if: matrix.symfony != '' + run: | + composer require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" + composer config extra.symfony.require "${{ matrix.symfony }}" + + - + name: Restrict Sylius version + if: matrix.sylius != '' + run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction + - name: Get Composer cache directory id: composer-cache @@ -89,10 +106,6 @@ jobs: (cd tests/Application && bin/console doctrine:database:create -vvv) (cd tests/Application && bin/console doctrine:schema:create -vvv) - - - name: Validate composer.json - run: composer validate --ansi --strict - - name: Run PHPStan run: vendor/bin/phpstan analyse -c phpstan.neon --no-progress src diff --git a/.gitignore b/.gitignore index 144dfda85..031b433dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea /composer.lock /vendor/ /bin/* diff --git a/composer.json b/composer.json index edcae60a2..4771f743b 100644 --- a/composer.json +++ b/composer.json @@ -7,21 +7,23 @@ "php": "^7.3", "sylius/sylius": "^1.8", "lexik/jwt-authentication-bundle": "^2.5", - "symfony/messenger": "^4.4" + "symfony/messenger": "^4.4|5.2", + "doctrine/doctrine-bundle": "^2.0", + "friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev" }, "require-dev": { - "lchrusciel/api-test-case": "^4.0", + "lchrusciel/api-test-case": "^5.1", "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^4.0", - "phpspec/phpspec": "^6.1", + "phpspec/phpspec": "^7.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-webmozart-assert": "^0.12", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^9.0", "sylius-labs/coding-standard": "^3.0", - "symfony/debug-bundle": "^4.1", - "symfony/dotenv": "^4.1", - "symfony/web-profiler-bundle": "^4.1", - "symfony/web-server-bundle": "^4.1", + "symfony/debug-bundle": "^4.4|5.2", + "symfony/dotenv": "^4.4|5.2", + "symfony/web-profiler-bundle": "^4.4|5.2", + "symfony/web-server-bundle": "^4.4", "mamazu/documentation-validator": "^1.0.1" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon index dece9cd63..aaf880929 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,6 +12,5 @@ parameters: ignoreErrors: - /^Access to an undefined property Symfony\\Component\\Validator\\Constraint::\$message\.$/ - - '/Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\)/' - '/Sylius\\Component\\Core\\Model\\(\w+), Sylius\\Component\\\w+\\Model\\\1 given\./' - '/Call to static method Webmozart\\Assert\\Assert::implementsInterface\(\) with string/' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 17d7eaf3f..6e24448cc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,20 @@ - - - - - ./tests - - - - - - - - - - - - ./tests/Application - ./tests/DataFixtures - ./tests/Responses - - + + + + ./tests/Application + ./tests/DataFixtures + ./tests/Responses + + + + + ./tests + + + + + + + diff --git a/spec/EventListener/UserRegistrationListenerSpec.php b/spec/EventListener/UserRegistrationListenerSpec.php index 2321ec9b9..c2621dcc0 100644 --- a/spec/EventListener/UserRegistrationListenerSpec.php +++ b/spec/EventListener/UserRegistrationListenerSpec.php @@ -4,7 +4,7 @@ namespace spec\Sylius\ShopApiPlugin\EventListener; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityManagerInterface; use PhpSpec\ObjectBehavior; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -23,7 +23,7 @@ function let( MessageBusInterface $bus, ChannelRepositoryInterface $channelRepository, UserRepositoryInterface $userRepository, - ObjectManager $userManager + EntityManagerInterface $userManager ): void { $this->beConstructedWith($bus, $channelRepository, $userRepository, $userManager); } diff --git a/spec/Http/RequestChannelEnsurerSpec.php b/spec/Http/RequestChannelEnsurerSpec.php index 26e441c17..1794f715c 100644 --- a/spec/Http/RequestChannelEnsurerSpec.php +++ b/spec/Http/RequestChannelEnsurerSpec.php @@ -11,8 +11,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpKernel\HttpKernelInterface; final class RequestChannelEnsurerSpec extends ObjectBehavior { @@ -28,10 +29,16 @@ function it_implements_event_subscriber_interface(): void function it_ensures_that_channel_code_passed_in_request_is_valid( ChannelExistenceCheckerInterface $channelExistenceChecker, - FilterControllerEvent $event, + HttpKernelInterface $kernel, Request $request ): void { - $event->getRequest()->willReturn($request); + $event = new ControllerEvent( + $kernel->getWrappedObject(), + function () {}, + $request->getWrappedObject(), + HttpKernelInterface::MASTER_REQUEST + ); + $request->attributes = new ParameterBag(['channelCode' => 'WEB_US']); $channelExistenceChecker->withCode('WEB_US')->willThrow(ChannelNotFoundException::class); @@ -44,10 +51,16 @@ function it_ensures_that_channel_code_passed_in_request_is_valid( function it_does_nothing_if_there_is_no_channel_code_in_request_attributes( ChannelExistenceCheckerInterface $channelExistenceChecker, - FilterControllerEvent $event, + HttpKernelInterface $kernel, Request $request ): void { - $event->getRequest()->willReturn($request); + $event = new ControllerEvent( + $kernel->getWrappedObject(), + function () {}, + $request->getWrappedObject(), + HttpKernelInterface::MASTER_REQUEST + ); + $request->attributes = new ParameterBag([]); $channelExistenceChecker->withCode(Argument::any())->shouldNotBeCalled(); diff --git a/spec/Modifier/OrderModifierSpec.php b/spec/Modifier/OrderModifierSpec.php index 810225365..6c29bf6c1 100644 --- a/spec/Modifier/OrderModifierSpec.php +++ b/spec/Modifier/OrderModifierSpec.php @@ -5,7 +5,7 @@ namespace spec\Sylius\ShopApiPlugin\Modifier; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityManagerInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Sylius\Component\Core\Factory\CartItemFactoryInterface; @@ -23,7 +23,7 @@ function let( CartItemFactoryInterface $cartItemFactory, OrderItemQuantityModifierInterface $orderItemQuantityModifier, OrderProcessorInterface $orderProcessor, - ObjectManager $orderManager + EntityManagerInterface $orderManager ): void { $this->beConstructedWith($cartItemFactory, $orderItemQuantityModifier, $orderProcessor, $orderManager); } @@ -36,7 +36,7 @@ function it_is_an_order_modifier_interface(): void function it_modifies_quantity_of_existing_item_with_the_same_variant_if_it_exist( OrderItemQuantityModifierInterface $orderItemQuantityModifier, OrderProcessorInterface $orderProcessor, - ObjectManager $orderManager, + EntityManagerInterface $orderManager, OrderInterface $order, OrderItemInterface $existingItem, ProductVariantInterface $productVariant @@ -58,7 +58,7 @@ function it_creates_new_cart_item_and_add_it_to_order_with_proper_variant_and_qu CartItemFactoryInterface $cartItemFactory, OrderItemQuantityModifierInterface $orderItemQuantityModifier, OrderProcessorInterface $orderProcessor, - ObjectManager $orderManager, + EntityManagerInterface $orderManager, OrderInterface $order, OrderItemInterface $cartItem, ProductVariantInterface $productVariant @@ -82,7 +82,7 @@ function it_throws_an_exception_if_the_product_is_out_of_stock( CartItemFactoryInterface $cartItemFactory, OrderItemQuantityModifierInterface $orderItemQuantityModifier, OrderProcessorInterface $orderProcessor, - ObjectManager $orderManager, + EntityManagerInterface $orderManager, OrderInterface $order, OrderItemInterface $cartItem, ProductVariantInterface $productVariant, diff --git a/src/Event/CustomerRegistered.php b/src/Event/CustomerRegistered.php index afae1b41d..6e771509e 100644 --- a/src/Event/CustomerRegistered.php +++ b/src/Event/CustomerRegistered.php @@ -4,7 +4,7 @@ namespace Sylius\ShopApiPlugin\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; final class CustomerRegistered extends Event { diff --git a/src/Handler/Customer/RegisterCustomerHandler.php b/src/Handler/Customer/RegisterCustomerHandler.php index 9d71d961b..ff5967d10 100644 --- a/src/Handler/Customer/RegisterCustomerHandler.php +++ b/src/Handler/Customer/RegisterCustomerHandler.php @@ -66,14 +66,14 @@ public function __invoke(RegisterCustomer $command): void $this->userRepository->add($user); - $this->eventDispatcher->dispatch('sylius.customer.post_api_registered', new CustomerRegistered( + $this->eventDispatcher->dispatch(new CustomerRegistered( $command->email(), $command->firstName(), $command->lastName(), $command->channelCode(), $command->subscribedToNewsletter(), $command->phoneNumber() - )); + ), 'sylius.customer.post_api_registered'); } private function assertEmailIsNotTaken(string $email): void diff --git a/src/Http/RequestChannelEnsurer.php b/src/Http/RequestChannelEnsurer.php index 6b3e05b5f..c4b7ce030 100644 --- a/src/Http/RequestChannelEnsurer.php +++ b/src/Http/RequestChannelEnsurer.php @@ -7,7 +7,7 @@ use Sylius\ShopApiPlugin\Checker\ChannelExistenceCheckerInterface; use Sylius\ShopApiPlugin\Exception\ChannelNotFoundException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\KernelEvents; @@ -21,7 +21,7 @@ public function __construct(ChannelExistenceCheckerInterface $channelExistenceCh $this->channelExistenceChecker = $channelExistenceChecker; } - public function checkChannelCode(FilterControllerEvent $event): void + public function checkChannelCode(ControllerEvent $event): void { $requestAttributes = $event->getRequest()->attributes; diff --git a/src/Modifier/OrderModifier.php b/src/Modifier/OrderModifier.php index 10ac51b21..85cc5120d 100644 --- a/src/Modifier/OrderModifier.php +++ b/src/Modifier/OrderModifier.php @@ -4,7 +4,7 @@ namespace Sylius\ShopApiPlugin\Modifier; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityManagerInterface; use Sylius\Component\Core\Factory\CartItemFactoryInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemInterface; @@ -25,7 +25,7 @@ final class OrderModifier implements OrderModifierInterface /** @var OrderProcessorInterface */ private $orderProcessor; - /** @var ObjectManager */ + /** @var EntityManagerInterface */ private $orderManager; /** @var AvailabilityCheckerInterface|null */ @@ -35,7 +35,7 @@ public function __construct( CartItemFactoryInterface $cartItemFactory, OrderItemQuantityModifierInterface $orderItemQuantityModifier, OrderProcessorInterface $orderProcessor, - ObjectManager $orderManager, + EntityManagerInterface $orderManager, ?AvailabilityCheckerInterface $availabilityChecker = null ) { $this->cartItemFactory = $cartItemFactory; diff --git a/src/Resources/config/app/sylius_mailer.yml b/src/Resources/config/app/sylius_mailer.yml index 2b02cd8fa..24e0e7257 100644 --- a/src/Resources/config/app/sylius_mailer.yml +++ b/src/Resources/config/app/sylius_mailer.yml @@ -5,10 +5,10 @@ sylius_mailer: emails: api_verification_token: subject: sylius.emails.user.verification_token.subject - template: "SyliusShopApiPlugin:Email:verification.html.twig" + template: "@SyliusShopApiPlugin/Email/verification.html.twig" api_reset_password_token: subject: sylius.emails.user.reset_password_token.subject - template: "SyliusShopApiPlugin:Email:passwordReset.html.twig" + template: "@SyliusShopApiPlugin/Email/passwordReset.html.twig" api_order_confirmation: subject: sylius.emails.order_confirmation.subject - template: "SyliusShopApiPlugin:Email:orderConfirmation.html.twig" + template: "@SyliusShopApiPlugin/Email/orderConfirmation.html.twig" diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index dc6788d3e..7cdbffbca 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -48,5 +48,13 @@ + + + + + + + + diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index ce7ffa2f9..b04b0d6b1 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -85,7 +85,7 @@ protected function getContainerLoader(ContainerInterface $container): LoaderInte /** @var ContainerBuilder $container */ Assert::isInstanceOf($container, ContainerBuilder::class); - $locator = new FileLocator($this, $this->getRootDir() . '/Resources'); + $locator = new FileLocator($this); $resolver = new LoaderResolver([ new XmlFileLoader($container, $locator), new YamlFileLoader($container, $locator), diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index d948b6521..dc1bd5feb 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -7,7 +7,6 @@ Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true], Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], @@ -40,7 +39,7 @@ Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], - WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], diff --git a/tests/Application/config/packages/dev/jms_serializer.yaml b/tests/Application/config/packages/dev/jms_serializer.yaml index 353e46027..2f32a9b18 100644 --- a/tests/Application/config/packages/dev/jms_serializer.yaml +++ b/tests/Application/config/packages/dev/jms_serializer.yaml @@ -1,6 +1,11 @@ jms_serializer: visitors: - json: + json_serialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: options: - JSON_PRETTY_PRINT - JSON_UNESCAPED_SLASHES diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml index e74ed811e..9b445011c 100644 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -2,6 +2,5 @@ framework: secret: '%env(APP_SECRET)%' form: true csrf_protection: true - templating: { engines: ["twig"] } session: handler_id: ~ diff --git a/tests/Application/config/packages/jms_serializer.yaml b/tests/Application/config/packages/jms_serializer.yaml index 64dd8d103..ed7bc613f 100644 --- a/tests/Application/config/packages/jms_serializer.yaml +++ b/tests/Application/config/packages/jms_serializer.yaml @@ -1,4 +1,4 @@ jms_serializer: visitors: - xml: + xml_serialization: format_output: '%kernel.debug%' diff --git a/tests/Application/config/packages/prod/jms_serializer.yaml b/tests/Application/config/packages/prod/jms_serializer.yaml index bc97faf1f..c2881820f 100644 --- a/tests/Application/config/packages/prod/jms_serializer.yaml +++ b/tests/Application/config/packages/prod/jms_serializer.yaml @@ -1,6 +1,10 @@ jms_serializer: visitors: - json: + json_serialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: options: - JSON_UNESCAPED_SLASHES - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/routes/dev/twig.yaml b/tests/Application/config/routes/dev/twig.yaml index f4ee83960..e69de29bb 100644 --- a/tests/Application/config/routes/dev/twig.yaml +++ b/tests/Application/config/routes/dev/twig.yaml @@ -1,3 +0,0 @@ -_errors: - resource: '@TwigBundle/Resources/config/routing/errors.xml' - prefix: /_error diff --git a/tests/Controller/Order/ShowApiTest.php b/tests/Controller/Order/ShowApiTest.php index cbf14e5ab..39f0d4209 100644 --- a/tests/Controller/Order/ShowApiTest.php +++ b/tests/Controller/Order/ShowApiTest.php @@ -83,7 +83,7 @@ public function it_returns_a_not_found_exception_if_placed_order_with_given_toke $this->placeOrderForCustomerWithEmail($email, $token); //logout - $this->client->setServerParameter('HTTP_Authorization', null); + $this->client->setServerParameter('HTTP_Authorization', ''); $response = $this->showOrder($token); $this->assertResponse($response, 'order/order_placed_by_registered_customer', Response::HTTP_NOT_FOUND);