Skip to content

Commit

Permalink
Merge pull request #703 from lchrusciel/sylius-1.9
Browse files Browse the repository at this point in the history
[Maintenance] Provide support for Sylius 1.9
  • Loading branch information
lchrusciel authored Mar 17, 2021
2 parents 13c6bbe + b08d11e commit e6bd790
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 72 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ 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
matrix:
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/composer.lock
/vendor/
/bin/*
Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
42 changes: 18 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Sylius Shop Api Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<php>
<server name="KERNEL_CLASS" value="Tests\Sylius\ShopApiPlugin\Application\Kernel" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
<server name="ESCAPE_JSON" value="true" />
</php>

<filter>
<whitelist>
<directory>./tests/Application</directory>
<directory>./tests/DataFixtures</directory>
<directory>./tests/Responses</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./tests/Application</directory>
<directory>./tests/DataFixtures</directory>
<directory>./tests/Responses</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Sylius Shop Api Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_CLASS" value="Tests\Sylius\ShopApiPlugin\Application\Kernel"/>
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true"/>
<server name="ESCAPE_JSON" value="true"/>
</php>
</phpunit>
4 changes: 2 additions & 2 deletions spec/EventListener/UserRegistrationListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +23,7 @@ function let(
MessageBusInterface $bus,
ChannelRepositoryInterface $channelRepository,
UserRepositoryInterface $userRepository,
ObjectManager $userManager
EntityManagerInterface $userManager
): void {
$this->beConstructedWith($bus, $channelRepository, $userRepository, $userManager);
}
Expand Down
23 changes: 18 additions & 5 deletions spec/Http/RequestChannelEnsurerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions spec/Modifier/OrderModifierSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +23,7 @@ function let(
CartItemFactoryInterface $cartItemFactory,
OrderItemQuantityModifierInterface $orderItemQuantityModifier,
OrderProcessorInterface $orderProcessor,
ObjectManager $orderManager
EntityManagerInterface $orderManager
): void {
$this->beConstructedWith($cartItemFactory, $orderItemQuantityModifier, $orderProcessor, $orderManager);
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Event/CustomerRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sylius\ShopApiPlugin\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

final class CustomerRegistered extends Event
{
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/Customer/RegisterCustomerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Http/RequestChannelEnsurer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Modifier/OrderModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +25,7 @@ final class OrderModifier implements OrderModifierInterface
/** @var OrderProcessorInterface */
private $orderProcessor;

/** @var ObjectManager */
/** @var EntityManagerInterface */
private $orderManager;

/** @var AvailabilityCheckerInterface|null */
Expand All @@ -35,7 +35,7 @@ public function __construct(
CartItemFactoryInterface $cartItemFactory,
OrderItemQuantityModifierInterface $orderItemQuantityModifier,
OrderProcessorInterface $orderProcessor,
ObjectManager $orderManager,
EntityManagerInterface $orderManager,
?AvailabilityCheckerInterface $availabilityChecker = null
) {
$this->cartItemFactory = $cartItemFactory;
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/app/sylius_mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 8 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,13 @@
<argument type="service" id="sylius.context.channel" />
<argument type="service" id="sylius.shop_api_plugin.command_provider.pickup_cart" />
</service>


<!-- TODO: Remove this definition when LocaleSetter tag priority will be fixed on Sylius/Sylius (changed from 4 to >16) -->
<service id="sylius.listener.request_locale_setter" class="Sylius\Bundle\LocaleBundle\Listener\RequestLocaleSetter">
<argument type="service" id="sylius.context.locale" />
<argument type="service" id="sylius.locale_provider" />
<tag name="kernel.event_listener" event="kernel.request" priority="25" />
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
7 changes: 6 additions & 1 deletion tests/Application/config/packages/dev/jms_serializer.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit e6bd790

Please sign in to comment.