Skip to content

Commit

Permalink
Merge pull request #40 from BitBagCommerce/feature/OP-121
Browse files Browse the repository at this point in the history
OP-144/Sylius upgrade
  • Loading branch information
senghe authored Apr 21, 2023
2 parents b742299 + 009a19b commit c1ee07d
Show file tree
Hide file tree
Showing 65 changed files with 349 additions and 665 deletions.
27 changes: 9 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,23 @@ on:

jobs:
tests:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"

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

exclude:
-
sylius: ~1.8.0
symfony: ^5.2
-
sylius: ~1.8.0
php: 8.0
-
sylius: ~1.9.0
php: 8.0
-
sylius: ~1.11.0
php: 7.4
symfony: ^6.0

env:
APP_ENV: test
Expand Down Expand Up @@ -144,13 +135,13 @@ jobs:
name: Prepare test application database
run: |
(cd tests/Application && bin/console doctrine:database:create -vvv)
(cd tests/Application && bin/console doctrine:schema:create -vvv)
(cd tests/Application && bin/console doctrine:schema:create -vvv)
-
name: Prepare test application assets
run: |
(cd tests/Application && bin/console assets:install public -vvv)
(cd tests/Application && yarn build)
(cd tests/Application && yarn encore dev)
-
name: Prepare test application cache
Expand Down
30 changes: 11 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"description": "Shipping data export environment for Sylius platform applications",
"license": "MIT",
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.0",
"bitbag/coding-standard": "^1.0.1 || ^2.0.0",
"sylius/sylius": "~1.8.0 || ~1.9.0 || ~1.10.0 || ~1.11.0"
"doctrine/dbal": "^2.7",
"sylius/sylius": "~1.11.0 || ~1.12.0"
},
"require-dev": {
"behat/behat": "^3.6.1",
"symfony/webpack-encore-bundle": "^1.15",
"behat/mink-selenium2-driver": "^1.4",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
Expand All @@ -28,16 +30,14 @@
"phpstan/phpstan-strict-rules": "^0.12.0 || ^1.0",
"phpstan/phpstan-webmozart-assert": "0.12.12 || ^1.0",
"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",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev"
"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",
"vimeo/psalm": "4.7.1 || ^5.0.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
},
"config": {
"sort-packages": true,
Expand All @@ -48,14 +48,6 @@
"phpstan/extension-installer": true
}
},
"conflict": {
"doctrine/dbal": "^3.0",
"symfony/symfony": "4.1.8",
"symfony/browser-kit": "4.1.8",
"symfony/dom-crawler": "4.1.8",
"symfony/routing": "4.1.8",
"symfony/doctrine-bridge": "4.4.16"
},
"autoload": {
"psr-4": {
"BitBag\\SyliusShippingExportPlugin\\": "src/",
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

excludes_analyse:
# Makes PHPStan crash
Expand All @@ -11,4 +12,6 @@ parameters:
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '/Cannot call method [a-z]+Node\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\./'

4 changes: 4 additions & 0 deletions spec/Controller/ShippingExportDownloadLabelActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function it_should_not_allow_directory_travelsal(
}

function it_returns_a_streamed_response_for_label(
Filesystem $filesystem,
Request $request,
ShippingExportRepositoryInterface $repository,
ShippingExportInterface $shippingExport
Expand All @@ -59,13 +60,16 @@ function it_returns_a_streamed_response_for_label(
$repository->find(1)
->willReturn($shippingExport)
;
$filesystem->exists('/var/www/shipping_labels/label.pdf')->willReturn(true);

$this->__invoke($request)
->shouldBeAnInstanceOf(StreamedResponse::class)
;

$this->__invoke($request)
->headers->get('Content-Disposition')
->shouldReturn('attachment; filename=label.pdf')
;
}

}
5 changes: 4 additions & 1 deletion src/Controller/ShippingExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sylius\Component\Resource\Model\ResourceInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Webmozart\Assert\Assert;

final class ShippingExportController extends ResourceController
Expand All @@ -28,7 +29,9 @@ public function exportAllNewShipmentsAction(Request $request): RedirectResponse
$shippingExports = $this->repository->findAllWithNewOrPendingState();

if (0 === count($shippingExports)) {
$this->addFlash('error', 'bitbag.ui.no_new_shipments_to_export');
/** @var FlashBagInterface $flashBag */
$flashBag = $request->getSession()->getBag('flashes');
$flashBag->add('error', 'bitbag.ui.no_new_shipments_to_export');

return $this->redirectToReferer($request);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/ShippingExportDownloadLabelAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace BitBag\SyliusShippingExportPlugin\Controller;

use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function __construct(

public function __invoke(Request $request): Response
{
/** @var ?ShippingExportInterface $shippingExport */
$shippingExport = $this->repository->find($request->get('id'));
Assert::notNull($shippingExport);
$labelPath = $shippingExport->getLabelPath();
Expand Down
7 changes: 7 additions & 0 deletions src/Repository/ShippingGatewayRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@

use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Shipping\Model\ShippingMethodInterface;

/**
* @template T of ResourceInterface
*
* @extends RepositoryInterface<T>
*/
interface ShippingGatewayRepositoryInterface extends RepositoryInterface
{
public function createListQueryBuilder(): QueryBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/routing/bitbag_shipping_export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ bitbag_admin_export_all_new_shipments:
path: /shipping-exports/export/all
methods: [POST, PUT]
defaults:
_controller: bitbag.controller.shipping_export:exportAllNewShipmentsAction
_controller: bitbag.controller.shipping_export::exportAllNewShipmentsAction

bitbag_admin_export_single_shipment:
path: /shipping-exports/export/{id}
methods: [POST, PUT]
defaults:
_controller: bitbag.controller.shipping_export:exportSingleShipmentAction
_controller: bitbag.controller.shipping_export::exportSingleShipmentAction

bitbag_admin_get_shipping_label:
path: /shipping-exports/label/{id}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/routing/bitbag_shipping_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bitbag_admin_shipping_gateway_create:
path: /shipping-gateways/new/{code}
methods: [GET, POST]
defaults:
_controller: bitbag.controller.shipping_gateway:createAction
_controller: bitbag.controller.shipping_gateway::createAction
_sylius:
section: admin
template: '@SyliusAdmin/Crud/create.html.twig'
Expand Down
12 changes: 7 additions & 5 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;

final class Kernel extends BaseKernel
Expand Down Expand Up @@ -58,7 +59,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
}
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
protected function configureRoutes(RoutingConfigurator $routes): void
{
foreach ($this->getConfigurationDirectories() as $confDir) {
$this->loadRoutesConfiguration($routes, $confDir);
Expand Down Expand Up @@ -87,11 +88,11 @@ private function loadContainerConfiguration(LoaderInterface $loader, string $con
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
}

private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void
private function loadRoutesConfiguration(RoutingConfigurator $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');
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS);
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS);
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS);
}

/**
Expand All @@ -103,6 +104,7 @@ private function registerBundlesFromFile(string $bundlesFile): iterable
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();

}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Application/assets/admin/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'sylius/bundle/AdminBundle/Resources/private/entry';
1 change: 1 addition & 0 deletions tests/Application/assets/shop/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'sylius/bundle/ShopBundle/Resources/private/entry';
2 changes: 1 addition & 1 deletion tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
// load all the .env files
(new Dotenv(true))->loadEnv(dirname(__DIR__) . '/.env');
(new Dotenv())->loadEnv(dirname(__DIR__) . '/.env');
}

$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
Expand Down
8 changes: 7 additions & 1 deletion tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?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
*/

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true],
Expand Down Expand Up @@ -54,4 +59,5 @@
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all'=> true],
];
4 changes: 4 additions & 0 deletions tests/Application/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ framework:
form: true
csrf_protection: true
session:
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
handler_id: ~
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
9 changes: 0 additions & 9 deletions tests/Application/config/packages/security_checker.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Application/config/packages/test/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
framework:
test: ~
session:
storage_id: session.storage.mock_file
handler_id: ~
5 changes: 5 additions & 0 deletions tests/Application/config/packages/webpack_encore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
webpack_encore:
output_path: '%kernel.project_dir%/public/build/default'
builds:
shop: '%kernel.project_dir%/public/build/shop'
admin: '%kernel.project_dir%/public/build/admin'
2 changes: 1 addition & 1 deletion tests/Application/config/routes/sylius_shop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ sylius_shop_default_locale:
path: /
methods: [GET]
defaults:
_controller: sylius.controller.shop.locale_switch:switchAction
_controller: sylius.controller.shop.locale_switch::switchAction
6 changes: 0 additions & 6 deletions tests/Application/config/sylius/1.10/bundles.php

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c1ee07d

Please sign in to comment.