Skip to content

Commit

Permalink
Merge pull request #458 from BitBagCommerce/feature/add-sylius-1.12-s…
Browse files Browse the repository at this point in the history
…upport

Feature/add sylius 1.12 support
  • Loading branch information
mpysiak committed Jan 17, 2023
2 parents 533fbdc + d05bf38 commit 3df6064
Show file tree
Hide file tree
Showing 95 changed files with 472 additions and 601 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,15 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "7.4"]
symfony: ["^4.4", "^5.2"]
sylius: ["~1.9.0", "~1.10.0", "~1.11.0"]
node: ["14.19"]
php: ["8.0"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.11.0", "~1.12.0"]
node: ["^14.17.x"]
mysql: ["8.0"]

exclude:
- sylius: ~1.9.0
php: 8.0

- sylius: ~1.10.0
symfony: ^4.4

- sylius: ~1.11.0
php: 7.4
symfony: "^6.0"

env:
APP_ENV: test
Expand Down Expand Up @@ -132,6 +126,11 @@ jobs:
restore-keys: |
${{ runner.os }}-node-${{ matrix.node }}-yarn-
-
name: Copy package.json.dist to package.json
if: matrix.sylius != ''
run: (cd tests/Application && cp package.json.\${{ matrix.sylius }}.dist package.json)

-
name: Install JS dependencies
run: |
Expand Down
41 changes: 10 additions & 31 deletions .github/workflows/coding_standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,17 @@ jobs:
name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"

strategy:
fail-fast: false
matrix:
php: [7.4, 7.3, 8.0]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0, ~1.10.0, ~1.11.0]
node: [10.x]
mysql: [5.7]
fail-fast: false
matrix:
php: ["8.0"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.11.0", "~1.12.0"]
node: ["^14.17.x"]
mysql: ["8.0"]

exclude:
-
php: 7.3
mysql: 8.0
-
sylius: ~1.8.0
symfony: ^5.2
-
sylius: ~1.8.0
php: 8.0
-
sylius: ~1.9.0
php: 8.0
-
sylius: ~1.10.0
php: 7.3

-
sylius: ~1.11.0
php: 7.3

-
sylius: ~1.11.0
php: 7.4
exclude:
- sylius: ~1.11.0
symfony: "^6.0"

env:
APP_ENV: test
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"description": "CMS plugin for Sylius applications.",
"license": "MIT",
"require": {
"php": "^7.3 || ^7.4 || ^8.0",
"sylius/sylius": "~1.8.0 || ~1.9.0 || ~1.10.0 || ~1.11.0",
"php": "^8.0",
"sylius/sylius": "~1.11.0 || ~1.12.0",
"league/csv": "^9.1",
"friendsofsymfony/ckeditor-bundle": "^1.1||^2.0",
"friendsofsymfony/ckeditor-bundle": "^1.1 || ^2.0",
"instaclick/php-webdriver": "^1.4",
"symfony/webpack-encore-bundle": "^1.12"
},
Expand All @@ -30,25 +30,25 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"lchrusciel/api-test-case": "^4.1||^5.0",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"lchrusciel/api-test-case": "^4.1 || ^5.0",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^9.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^4.0",
"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",
"vimeo/psalm": "4.7.1",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"league/flysystem-bundle": "2.4.0",
"sylius/mailer-bundle": "^1.8 || ^2.0@beta",
"matthiasnoback/symfony-config-test": "^4.3",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"twig/twig": "^2.10.0"
},
"conflict": {
"symfony/symfony": "4.1.8",
Expand Down
6 changes: 3 additions & 3 deletions spec/MediaProvider/GenericProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@

final class GenericProviderSpec extends ObjectBehavior
{
public function let(
function let(
MediaUploaderInterface $uploader,
Environment $twigEngine
) {
$this->beConstructedWith($uploader, $twigEngine, '@Template', '/media/');
}

public function it_is_initializable(): void
function it_is_initializable(): void
{
$this->shouldHaveType(GenericProvider::class);
}

public function it_implements_provider_interface(): void
function it_implements_provider_interface(): void
{
$this->shouldHaveType(ProviderInterface::class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusCmsPlugin\MediaProvider;

use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
use BitBag\SyliusCmsPlugin\MediaProvider\GenericProvider;
use BitBag\SyliusCmsPlugin\MediaProvider\ProviderInterface;
use BitBag\SyliusCmsPlugin\Uploader\MediaUploaderInterface;
use PhpSpec\ObjectBehavior;
use Twig\Environment;

final class GenericProviderSpec extends ObjectBehavior
{
public function let(
MediaUploaderInterface $uploader,
Environment $twigEngine
) {
$this->beConstructedWith($uploader, $twigEngine, '@Template', '/media/');
}

public function it_is_initializable(): void
{
$this->shouldHaveType(GenericProvider::class);
}

public function it_implements_provider_interface(): void
{
$this->shouldHaveType(ProviderInterface::class);
}

public function it_renders(MediaInterface $media, Environment $twigEngine): void
{
$twigEngine->render('@Template', ['media' => $media, 'config' => []])->willReturn('content');

$this->render($media, '@Template', ['config' => []])->shouldReturn('content');
}

public function it_uploads(MediaInterface $media, MediaUploaderInterface $uploader): void
{
$uploader->upload($media, '/media/')->shouldNotBeCalled();
}
}
18 changes: 11 additions & 7 deletions src/Controller/Action/Admin/ImportDataAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

Expand All @@ -31,8 +32,8 @@ final class ImportDataAction
/** @var FormFactoryInterface */
private $formFactory;

/** @var FlashBagInterface */
private $flashBag;
/** @var RequestStack */
private $requestStack;

/** @var FormErrorsFlashHelperInterface */
private $formErrorsFlashHelper;
Expand All @@ -46,14 +47,14 @@ final class ImportDataAction
public function __construct(
ImportProcessorInterface $importProcessor,
FormFactoryInterface $formFactory,
FlashBagInterface $flashBag,
RequestStack $requestStack,
FormErrorsFlashHelperInterface $formErrorsFlashHelper,
TranslatorInterface $translator,
Environment $twig
) {
$this->importProcessor = $importProcessor;
$this->formFactory = $formFactory;
$this->flashBag = $flashBag;
$this->requestStack = $requestStack;
$this->formErrorsFlashHelper = $formErrorsFlashHelper;
$this->translator = $translator;
$this->twig = $twig;
Expand All @@ -71,13 +72,16 @@ public function __invoke(Request $request): Response
/** @var UploadedFile $file */
$file = $form->get('file')->getData();
$resourceName = $request->get('resourceName');
/** @var Session $session */
$session = $this->requestStack->getSession();
$flashBag = $session->getFlashBag();

try {
$this->importProcessor->process($resourceName, $file->getPathname());

$this->flashBag->set('success', $this->translator->trans('bitbag_sylius_cms_plugin.ui.successfully_imported'));
$flashBag->set('success', $this->translator->trans('bitbag_sylius_cms_plugin.ui.successfully_imported'));
} catch (ImportFailedException $exception) {
$this->flashBag->set('error', $exception->getMessage());
$flashBag->set('error', $exception->getMessage());
}
} else {
$this->formErrorsFlashHelper->addFlashErrors($form);
Expand Down
13 changes: 7 additions & 6 deletions src/Controller/Helper/FormErrorsFlashHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;

final class FormErrorsFlashHelper implements FormErrorsFlashHelperInterface
{
/** @var FlashBagInterface */
private $flashBag;
/** @var RequestStack */
private $requestStack;

/** @var TranslatorInterface */
private $translator;

public function __construct(FlashBagInterface $flashBag, TranslatorInterface $translator)
public function __construct(RequestStack $requestStack, TranslatorInterface $translator)
{
$this->flashBag = $flashBag;
$this->requestStack = $requestStack;
$this->translator = $translator;
}

Expand All @@ -43,6 +43,7 @@ public function addFlashErrors(FormInterface $form): void

$message = $this->translator->trans('bitbag_sylius_cms_plugin.ui.form_was_submitted_with_errors') . ' ' . rtrim(implode(' ', $errors));

$this->flashBag->set('error', $message);
$session = $this->requestStack->getSession()->getFlashBag();
$session->set('error', $message);
}
}
2 changes: 1 addition & 1 deletion src/Controller/ResourceDataProcessingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait ResourceDataProcessingTrait
{
private function getResourceInterface(Request $request): object
{
return null !== $request->get('id') && $this->repository->find($request->get('id')) ?
return null !== $request->get('id') && null !== $this->repository->find($request->get('id')) ?
$this->repository->find($request->get('id')) :
$this->factory->createNew();
}
Expand Down
17 changes: 8 additions & 9 deletions src/EventListener/ResourceDeleteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class ResourceDeleteSubscriber implements EventSubscriberInterface
{
/** @var UrlGeneratorInterface */
private $router;
private UrlGeneratorInterface $router;

/** @var SessionInterface */
private $session;
private RequestStack $requestStack;

public function __construct(UrlGeneratorInterface $router, SessionInterface $session)
public function __construct(UrlGeneratorInterface $router, RequestStack $requestStack)
{
$this->router = $router;
$this->session = $session;
$this->requestStack = $requestStack;
}

public static function getSubscribedEvents(): array
Expand All @@ -49,7 +47,7 @@ public function onResourceDelete(ExceptionEvent $event): void
return;
}

if (!$event->isMasterRequest() || 'html' !== $event->getRequest()->getRequestFormat()) {
if (!$event->isMainRequest() || 'html' !== $event->getRequest()->getRequestFormat()) {
return;
}

Expand All @@ -70,8 +68,9 @@ public function onResourceDelete(ExceptionEvent $event): void
return;
}

$session = $this->requestStack->getSession();
/** @var FlashBagInterface $flashBag */
$flashBag = $this->session->getBag('flashes');
$flashBag = $session->getBag('flashes');
$flashBag->add('error', [
'message' => 'sylius.resource.delete_error',
'parameters' => ['%resource%' => $resourceName],
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bitbag_sylius_cms_plugin_admin_ajax_generate_page_slug:
path: /page/generate-slug
methods: [GET]
defaults:
_controller: bitbag_sylius_cms_plugin.controller.page_slug:generateAction
_controller: bitbag_sylius_cms_plugin.controller.page_slug::generateAction

bitbag_sylius_cms_plugin_admin_import_data:
path: /import/{resourceName}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin/block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ bitbag_sylius_cms_plugin_admin_block_preview:
path: /block/preview
methods: [GET, POST, PUT]
defaults:
_controller: bitbag_sylius_cms_plugin.controller.block:previewAction
_controller: bitbag_sylius_cms_plugin.controller.block::previewAction
_sylius:
template: "@BitBagSyliusCmsPlugin/Block/preview.html.twig"
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin/locale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bitbag_sylius_cms_plugin_admin_partial_locale_index:
path: /_partial/locales
methods: [GET]
defaults:
_controller: sylius.controller.locale:indexAction
_controller: sylius.controller.locale::indexAction
_sylius:
repository:
method: findAll
Expand Down

0 comments on commit 3df6064

Please sign in to comment.