From 26b4dc58bf42d0df2b5ec3319fad025b192dc494 Mon Sep 17 00:00:00 2001 From: Tomanhez Date: Wed, 20 Jan 2021 10:49:18 +0100 Subject: [PATCH 1/2] Upgrade to sylius 1.9 --- composer.json | 15 ++++++++------- spec/Generator/InvoicePdfFileGeneratorSpec.php | 6 +++--- src/Generator/InvoicePdfFileGenerator.php | 6 +++--- src/Resources/config/services/generators.xml | 2 +- tests/Application/.env | 2 +- tests/Application/config/bundles.php | 3 +-- tests/Application/config/packages/_sylius.yaml | 1 + .../config/packages/dev/jms_serializer.yaml | 7 ++++++- tests/Application/config/packages/framework.yaml | 1 - .../config/packages/jms_serializer.yaml | 2 +- .../config/packages/prod/jms_serializer.yaml | 6 +++++- 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 0f723641..563df87c 100644 --- a/composer.json +++ b/composer.json @@ -6,11 +6,12 @@ "license": "MIT", "require": { "php": "^7.3", - "knplabs/knp-snappy-bundle": "^1.7", + "friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev", + "knplabs/knp-snappy-bundle": "^1.8", "ramsey/uuid": "^3.9", "sylius/grid-bundle": "^1.7", - "sylius/resource-bundle": "^1.6", - "sylius/sylius": "^1.8", + "sylius/resource-bundle": "^1.7", + "sylius/sylius": "dev-master", "symfony/config": "^4.4", "symfony/dependency-injection": "^4.4", "symfony/form": "^4.4", @@ -22,20 +23,20 @@ "symfony/routing": "^4.4" }, "require-dev": { - "behat/behat": "^3.6", - "behat/mink": "^1.8", + "behat/behat": "^3.6.1", "behat/mink-browserkit-driver": "^1.3", "behat/mink-extension": "^2.3", "behat/mink-selenium2-driver": "^1.4", + "friends-of-behat/mink": "^1.8", "friends-of-behat/page-object-extension": "^0.3", "friends-of-behat/suite-settings-extension": "^1.0", "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", "lakion/mink-debug-extension": "^1.2.3", "matthiasnoback/symfony-config-test": "^4.0", - "phpspec/phpspec": "^6.0", + "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "0.12.29", "phpstan/phpstan-doctrine": "^0.12", "phpstan/phpstan-symfony": "^0.12", "phpstan/phpstan-webmozart-assert": "^0.12", diff --git a/spec/Generator/InvoicePdfFileGeneratorSpec.php b/spec/Generator/InvoicePdfFileGeneratorSpec.php index 1f2e4ee1..754b5b61 100644 --- a/spec/Generator/InvoicePdfFileGeneratorSpec.php +++ b/spec/Generator/InvoicePdfFileGeneratorSpec.php @@ -10,13 +10,13 @@ use Sylius\InvoicingPlugin\Entity\InvoiceInterface; use Sylius\InvoicingPlugin\Generator\InvoicePdfFileGeneratorInterface; use Sylius\InvoicingPlugin\Model\InvoicePdf; -use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; use Symfony\Component\Config\FileLocatorInterface; +use Twig\Environment; final class InvoicePdfFileGeneratorSpec extends ObjectBehavior { function let( - EngineInterface $twig, + Environment $twig, GeneratorInterface $pdfGenerator, FileLocatorInterface $fileLocator ): void { @@ -36,7 +36,7 @@ function it_implements_invoice_pdf_file_generator_interface(): void function it_creates_invoice_pdf_with_generated_content_and_filename_basing_on_invoice_number( FileLocatorInterface $fileLocator, - EngineInterface $twig, + Environment $twig, GeneratorInterface $pdfGenerator, InvoiceInterface $invoice, ChannelInterface $channel diff --git a/src/Generator/InvoicePdfFileGenerator.php b/src/Generator/InvoicePdfFileGenerator.php index 330f8b78..7d56cb70 100644 --- a/src/Generator/InvoicePdfFileGenerator.php +++ b/src/Generator/InvoicePdfFileGenerator.php @@ -7,14 +7,14 @@ use Knp\Snappy\GeneratorInterface; use Sylius\InvoicingPlugin\Entity\InvoiceInterface; use Sylius\InvoicingPlugin\Model\InvoicePdf; -use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; use Symfony\Component\Config\FileLocatorInterface; +use Twig\Environment; final class InvoicePdfFileGenerator implements InvoicePdfFileGeneratorInterface { private const FILE_EXTENSION = '.pdf'; - /** @var EngineInterface */ + /** @var Environment */ private $templatingEngine; /** @var GeneratorInterface */ @@ -30,7 +30,7 @@ final class InvoicePdfFileGenerator implements InvoicePdfFileGeneratorInterface private $invoiceLogoPath; public function __construct( - EngineInterface $templatingEngine, + Environment $templatingEngine, GeneratorInterface $pdfGenerator, FileLocatorInterface $fileLocator, string $template, diff --git a/src/Resources/config/services/generators.xml b/src/Resources/config/services/generators.xml index 33d125c2..6c1657ff 100644 --- a/src/Resources/config/services/generators.xml +++ b/src/Resources/config/services/generators.xml @@ -24,7 +24,7 @@ - + @SyliusInvoicingPlugin/Invoice/Download/pdf.html.twig diff --git a/tests/Application/.env b/tests/Application/.env index 66935703..61493cad 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -12,7 +12,7 @@ APP_SECRET=EDITME # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_invoicing_plugin_%kernel.environment%?serverVersion=5.5 +DATABASE_URL=mysql://root@127.0.0.1/sylius_invoicing_plugin_%kernel.environment%?serverVersion=5.7 ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 3b2c1d41..78c53690 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,6 @@ 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], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], @@ -59,4 +57,5 @@ FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true], Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml index 88859c0c..0212fbc9 100644 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -8,6 +8,7 @@ imports: - { resource: "@SyliusInvoicingPlugin/Resources/config/config.yml" } + - { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" } parameters: sylius_core.public_dir: '%kernel.project_dir%/public' diff --git a/tests/Application/config/packages/dev/jms_serializer.yaml b/tests/Application/config/packages/dev/jms_serializer.yaml index 353e4602..2f32a9b1 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 e74ed811..9b445011 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 64dd8d10..ed7bc613 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 bc97faf1..c2881820 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 From 30e4e7bf4bb237a8fccac69cd0e4c2a9e88c7f6d Mon Sep 17 00:00:00 2001 From: Tomanhez Date: Wed, 3 Mar 2021 09:56:26 +0100 Subject: [PATCH 2/2] Next iteration --- .github/workflows/build.yml | 21 +++++- composer.json | 43 ++++++------ .../EventProducer/OrderPlacedProducerSpec.php | 2 +- src/DependencyInjection/Configuration.php | 4 +- src/Security/Voter/InvoiceVoter.php | 4 ++ tests/Application/.env | 2 +- tests/Application/config/bundles.php | 1 - .../Application/config/sylius/1.8/bundles.php | 6 ++ .../1.8/packages/dev/jms_serializer.yaml | 7 ++ .../config/sylius/1.8/packages/framework.yaml | 2 + .../sylius/1.8/packages/jms_serializer.yaml | 4 ++ .../1.8/packages/prod/jms_serializer.yaml | 6 ++ .../config/sylius/1.8/routes/dev/twig.yaml | 3 + .../Application/config/sylius/1.9/bundles.php | 6 ++ .../1.9}/packages/dev/jms_serializer.yaml | 0 .../1.9}/packages/jms_serializer.yaml | 0 .../1.9}/packages/prod/jms_serializer.yaml | 0 tests/Application/public/index.php | 6 +- tests/Application/src/Kernel.php | 70 ++++++++++++++----- .../Domain/GeneratingInvoiceContext.php | 2 +- tests/Behat/Context/Order/OrderContext.php | 2 +- tests/Behat/Context/Setup/ChannelContext.php | 2 +- tests/Behat/Context/Setup/OrderContext.php | 2 +- .../Fixture/ShopBillingDataFixtureTest.php | 2 +- 24 files changed, 144 insertions(+), 53 deletions(-) create mode 100644 tests/Application/config/sylius/1.8/bundles.php create mode 100644 tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.8/packages/framework.yaml create mode 100644 tests/Application/config/sylius/1.8/packages/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.8/routes/dev/twig.yaml create mode 100644 tests/Application/config/sylius/1.9/bundles.php rename tests/Application/config/{ => sylius/1.9}/packages/dev/jms_serializer.yaml (100%) rename tests/Application/config/{ => sylius/1.9}/packages/jms_serializer.yaml (100%) rename tests/Application/config/{ => sylius/1.9}/packages/prod/jms_serializer.yaml (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index de2e5018..21531197 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,12 +13,14 @@ jobs: tests: runs-on: ubuntu-latest - name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}, Node ${{ matrix.node }}" + name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}" strategy: fail-fast: false matrix: php: [7.4, 7.3] + symfony: [^4.4, ^5.2] + sylius: [~1.8.0, ~1.9.0] node: [10.x] mysql: [5.7, 8.0] @@ -26,6 +28,9 @@ jobs: - php: 7.3 mysql: 8.0 + - + sylius: ~1.8.0 + symfony: ^5.2 env: APP_ENV: test @@ -75,6 +80,18 @@ jobs: restore-keys: | ${{ runner.os }}-php-${{ matrix.php }}-composer- + - + name: Restrict Symfony version + if: matrix.symfony != '' + run: | + composer global 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: Install PHP dependencies run: composer install --no-interaction @@ -131,7 +148,7 @@ jobs: - name: Run Behat - run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun + run: vendor/bin/behat --colors --strict -vvv --no-interaction -f progress || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --rerun - name: Upload Behat logs diff --git a/composer.json b/composer.json index 563df87c..ebc7c78f 100644 --- a/composer.json +++ b/composer.json @@ -6,32 +6,32 @@ "license": "MIT", "require": { "php": "^7.3", - "friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev", "knplabs/knp-snappy-bundle": "^1.8", "ramsey/uuid": "^3.9", "sylius/grid-bundle": "^1.7", - "sylius/resource-bundle": "^1.7", - "sylius/sylius": "dev-master", - "symfony/config": "^4.4", - "symfony/dependency-injection": "^4.4", - "symfony/form": "^4.4", - "symfony/framework-bundle": "^4.4", - "symfony/http-foundation": "^4.4", - "symfony/http-kernel": "^4.4", - "symfony/messenger": "^4.4", - "symfony/options-resolver": "^4.4", - "symfony/routing": "^4.4" + "sylius/resource-bundle": "^1.6", + "sylius/sylius": "~1.8.0 || ^1.9.0-RC.1", + "symfony/config": "^4.4 || ^5.2", + "symfony/dependency-injection": "^4.4 || ^5.2", + "symfony/form": "^4.4 || ^5.2", + "symfony/framework-bundle": "^4.4 || ^5.2", + "symfony/http-foundation": "^4.4 || ^5.2", + "symfony/http-kernel": "^4.4 || ^5.2", + "symfony/messenger": "^4.4 || ^5.2", + "symfony/options-resolver": "^4.4 || ^5.2", + "symfony/routing": "^4.4 || ^5.2" }, "require-dev": { "behat/behat": "^3.6.1", - "behat/mink-browserkit-driver": "^1.3", - "behat/mink-extension": "^2.3", "behat/mink-selenium2-driver": "^1.4", "friends-of-behat/mink": "^1.8", + "friends-of-behat/mink-browserkit-driver": "^1.3", + "friends-of-behat/mink-extension": "^2.3", "friends-of-behat/page-object-extension": "^0.3", "friends-of-behat/suite-settings-extension": "^1.0", "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", + "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev", "lakion/mink-debug-extension": "^1.2.3", "matthiasnoback/symfony-config-test": "^4.0", "phpspec/phpspec": "^7.0", @@ -42,12 +42,12 @@ "phpstan/phpstan-webmozart-assert": "^0.12", "phpunit/phpunit": "^8.5", "sylius-labs/coding-standard": "^3.2", - "symfony/browser-kit": "^4.4", - "symfony/debug-bundle": "^4.4", - "symfony/dotenv": "^4.4", - "symfony/intl": "^4.4", - "symfony/web-profiler-bundle": "^4.4", - "symfony/web-server-bundle": "^4.4" + "symfony/browser-kit": "^4.4 || ^5.2", + "symfony/debug-bundle": "^4.4 || ^5.2", + "symfony/dotenv": "^4.4 || ^5.2", + "symfony/intl": "^4.4 || ^5.2", + "symfony/web-profiler-bundle": "^4.4 || ^5.2", + "symfony/web-server-bundle": "^4.4 || ^5.2" }, "conflict": { "symplify/package-builder": "^8.3.25" @@ -67,8 +67,7 @@ "scripts": { "analyse": [ "@composer validate --strict", - "vendor/bin/phpstan analyse -c phpstan.neon -l max src/", - "vendor/bin/ecs check src/ spec/" + "vendor/bin/phpstan analyse -c phpstan.neon -l max src/" ], "fix": [ "vendor/bin/ecs check --fix src/ spec/" diff --git a/spec/EventProducer/OrderPlacedProducerSpec.php b/spec/EventProducer/OrderPlacedProducerSpec.php index 4b21663d..dd519cd7 100644 --- a/spec/EventProducer/OrderPlacedProducerSpec.php +++ b/spec/EventProducer/OrderPlacedProducerSpec.php @@ -4,7 +4,7 @@ namespace spec\Sylius\InvoicingPlugin\EventProducer; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\UnitOfWork; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index c360463d..0e3a2a37 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -26,8 +26,8 @@ final class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder(): TreeBuilder { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('sylius_invoicing_plugin'); + $treeBuilder = new TreeBuilder('sylius_invoicing_plugin'); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->children() diff --git a/src/Security/Voter/InvoiceVoter.php b/src/Security/Voter/InvoiceVoter.php index 86a2f07e..4633d7a1 100644 --- a/src/Security/Voter/InvoiceVoter.php +++ b/src/Security/Voter/InvoiceVoter.php @@ -41,6 +41,10 @@ protected function supports($attribute, $subject): bool return true; } + /** + * @param mixed $attribute + * @param mixed $subject + */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { Assert::isInstanceOf($subject, InvoiceInterface::class); diff --git a/tests/Application/.env b/tests/Application/.env index 61493cad..eebf920e 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -12,7 +12,7 @@ APP_SECRET=EDITME # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_invoicing_plugin_%kernel.environment%?serverVersion=5.7 +DATABASE_URL=mysql://root@127.0.0.1/sylius_invoicing_plugin_%kernel.environment% ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 78c53690..eb5fc3cc 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -57,5 +57,4 @@ FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true], Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], - BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/sylius/1.8/bundles.php b/tests/Application/config/sylius/1.8/bundles.php new file mode 100644 index 00000000..74ee2bc0 --- /dev/null +++ b/tests/Application/config/sylius/1.8/bundles.php @@ -0,0 +1,6 @@ + ['all' => true], + WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml new file mode 100644 index 00000000..353e4602 --- /dev/null +++ b/tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml @@ -0,0 +1,7 @@ +jms_serializer: + visitors: + json: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.8/packages/framework.yaml b/tests/Application/config/sylius/1.8/packages/framework.yaml new file mode 100644 index 00000000..62f82d35 --- /dev/null +++ b/tests/Application/config/sylius/1.8/packages/framework.yaml @@ -0,0 +1,2 @@ +framework: + templating: { engines: ["twig"] } diff --git a/tests/Application/config/sylius/1.8/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.8/packages/jms_serializer.yaml new file mode 100644 index 00000000..64dd8d10 --- /dev/null +++ b/tests/Application/config/sylius/1.8/packages/jms_serializer.yaml @@ -0,0 +1,4 @@ +jms_serializer: + visitors: + xml: + format_output: '%kernel.debug%' diff --git a/tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml new file mode 100644 index 00000000..bc97faf1 --- /dev/null +++ b/tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml @@ -0,0 +1,6 @@ +jms_serializer: + visitors: + json: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.8/routes/dev/twig.yaml b/tests/Application/config/sylius/1.8/routes/dev/twig.yaml new file mode 100644 index 00000000..f4ee8396 --- /dev/null +++ b/tests/Application/config/sylius/1.8/routes/dev/twig.yaml @@ -0,0 +1,3 @@ +_errors: + resource: '@TwigBundle/Resources/config/routing/errors.xml' + prefix: /_error diff --git a/tests/Application/config/sylius/1.9/bundles.php b/tests/Application/config/sylius/1.9/bundles.php new file mode 100644 index 00000000..bd33f4ae --- /dev/null +++ b/tests/Application/config/sylius/1.9/bundles.php @@ -0,0 +1,6 @@ + ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.9/packages/dev/jms_serializer.yaml similarity index 100% rename from tests/Application/config/packages/dev/jms_serializer.yaml rename to tests/Application/config/sylius/1.9/packages/dev/jms_serializer.yaml diff --git a/tests/Application/config/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.9/packages/jms_serializer.yaml similarity index 100% rename from tests/Application/config/packages/jms_serializer.yaml rename to tests/Application/config/sylius/1.9/packages/jms_serializer.yaml diff --git a/tests/Application/config/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.9/packages/prod/jms_serializer.yaml similarity index 100% rename from tests/Application/config/packages/prod/jms_serializer.yaml rename to tests/Application/config/sylius/1.9/packages/prod/jms_serializer.yaml diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php index e3ec2a2e..a575bc4f 100644 --- a/tests/Application/public/index.php +++ b/tests/Application/public/index.php @@ -2,12 +2,12 @@ declare(strict_types=1); -use Symfony\Component\Debug\Debug; +use Symfony\Component\ErrorHandler\Debug; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\HttpFoundation\Request; use Tests\Sylius\InvoicingPlugin\Application\Kernel; -require __DIR__.'/../../../vendor/autoload.php'; +require __DIR__ . '/../../../vendor/autoload.php'; // The check is to ensure we don't use .env in production if (!isset($_SERVER['APP_ENV']) && !isset($_ENV['APP_ENV'])) { @@ -15,7 +15,7 @@ throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'); } - $envFile = file_exists(__DIR__.'/../.env') ? __DIR__.'/../.env' : __DIR__.'/../.env.dist'; + $envFile = file_exists(__DIR__ . '/../.env') ? __DIR__ . '/../.env' : __DIR__ . '/../.env.dist'; (new Dotenv())->load($envFile); } diff --git a/tests/Application/src/Kernel.php b/tests/Application/src/Kernel.php index d3d0014b..d8fe5244 100644 --- a/tests/Application/src/Kernel.php +++ b/tests/Application/src/Kernel.php @@ -5,6 +5,7 @@ namespace Tests\Sylius\InvoicingPlugin\Application; use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; +use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\LoaderInterface; @@ -19,6 +20,7 @@ use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\RouteCollectionBuilder; @@ -42,31 +44,29 @@ public function getLogDir(): string public function registerBundles(): iterable { - $contents = require $this->getProjectDir() . '/config/bundles.php'; - foreach ($contents as $class => $envs) { - if (isset($envs['all']) || isset($envs[$this->environment])) { - yield new $class(); - } + foreach ($this->getConfigurationDirectories() as $confDir) { + yield from $this->registerBundlesFromFile($confDir . '/bundles.php'); } } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { - $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); + foreach ($this->getConfigurationDirectories() as $confDir) { + $container->addResource(new FileResource($confDir . '/bundles.php')); + } + $container->setParameter('container.dumper.inline_class_loader', true); - $confDir = $this->getProjectDir() . '/config'; - $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); + + foreach ($this->getConfigurationDirectories() as $confDir) { + $this->loadContainerConfiguration($loader, $confDir); + } } protected function configureRoutes(RouteCollectionBuilder $routes): void { - $confDir = $this->getProjectDir() . '/config'; - $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); - $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); - $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); + foreach ($this->getConfigurationDirectories() as $confDir) { + $this->loadRoutesConfiguration($routes, $confDir); + } } protected function getContainerBaseClass(): string @@ -81,7 +81,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, $this->getProjectDir() . '/src/Resources'); $resolver = new LoaderResolver(array( new XmlFileLoader($container, $locator), new YamlFileLoader($container, $locator), @@ -98,4 +98,42 @@ private function isTestEnvironment(): bool { return 0 === strpos($this->getEnvironment(), 'test'); } + + + private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void + { + $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); + $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); + $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); + $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); + } + + private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void + { + $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); + $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); + $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); + } + + /** + * @return BundleInterface[] + */ + private function registerBundlesFromFile(string $bundlesFile): iterable + { + $contents = require $bundlesFile; + foreach ($contents as $class => $envs) { + if (isset($envs['all']) || isset($envs[$this->environment])) { + yield new $class(); + } + } + } + + /** + * @return string[] + */ + private function getConfigurationDirectories(): iterable + { + yield $this->getProjectDir() . '/config'; + yield $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION; + } } diff --git a/tests/Behat/Context/Domain/GeneratingInvoiceContext.php b/tests/Behat/Context/Domain/GeneratingInvoiceContext.php index 8b1b25e2..0ef383a8 100644 --- a/tests/Behat/Context/Domain/GeneratingInvoiceContext.php +++ b/tests/Behat/Context/Domain/GeneratingInvoiceContext.php @@ -5,7 +5,7 @@ namespace Tests\Sylius\InvoicingPlugin\Behat\Context\Domain; use Behat\Behat\Context\Context; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface; final class GeneratingInvoiceContext implements Context diff --git a/tests/Behat/Context/Order/OrderContext.php b/tests/Behat/Context/Order/OrderContext.php index bef06e31..31452825 100644 --- a/tests/Behat/Context/Order/OrderContext.php +++ b/tests/Behat/Context/Order/OrderContext.php @@ -5,7 +5,7 @@ namespace Tests\Sylius\InvoicingPlugin\Behat\Context\Order; use Behat\Behat\Context\Context; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use SM\Factory\FactoryInterface as StateMachineFactoryInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Payment\PaymentTransitions; diff --git a/tests/Behat/Context/Setup/ChannelContext.php b/tests/Behat/Context/Setup/ChannelContext.php index 94a389fe..673e33b2 100644 --- a/tests/Behat/Context/Setup/ChannelContext.php +++ b/tests/Behat/Context/Setup/ChannelContext.php @@ -5,7 +5,7 @@ namespace Tests\Sylius\InvoicingPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Sylius\Component\Addressing\Model\CountryInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ShopBillingData; diff --git a/tests/Behat/Context/Setup/OrderContext.php b/tests/Behat/Context/Setup/OrderContext.php index 4596be6f..e05d4c20 100644 --- a/tests/Behat/Context/Setup/OrderContext.php +++ b/tests/Behat/Context/Setup/OrderContext.php @@ -5,7 +5,7 @@ namespace Tests\Sylius\InvoicingPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\OrderInterface; diff --git a/tests/Unit/Fixture/ShopBillingDataFixtureTest.php b/tests/Unit/Fixture/ShopBillingDataFixtureTest.php index 042fca05..6ab3b61e 100644 --- a/tests/Unit/Fixture/ShopBillingDataFixtureTest.php +++ b/tests/Unit/Fixture/ShopBillingDataFixtureTest.php @@ -4,7 +4,7 @@ namespace Tests\Sylius\InvoicingPlugin\Unit\Fixture; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; use PHPUnit\Framework\TestCase; use Sylius\InvoicingPlugin\Fixture\ShopBillingDataFixture;