Skip to content

Commit 4ee1c2b

Browse files
committed
Update to Sylius 1.9 based on sylius/plugin-skeleton
1 parent f0508be commit 4ee1c2b

39 files changed

+357
-104
lines changed

composer.json

+28-24
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@
44
"description": "Shipping data export environment for Sylius platform applications",
55
"license": "MIT",
66
"require": {
7-
"php": "^7.2",
8-
9-
"sylius/sylius": "^1.4"
7+
"php": "^7.3",
8+
"sylius/sylius": "~1.8.0 || ~1.9.0"
109
},
1110
"require-dev": {
12-
"behat/behat": "^3.4",
13-
"behat/mink": "^1.7@dev",
14-
"behat/mink-browserkit-driver": "^1.3",
15-
"behat/mink-extension": "^2.2",
16-
"behat/mink-selenium2-driver": "^1.3",
11+
"behat/behat": "^3.6.1",
12+
"behat/mink-selenium2-driver": "^1.4",
13+
"dmore/behat-chrome-extension": "^1.3",
14+
"dmore/chrome-mink-driver": "^2.7",
15+
"friends-of-behat/mink": "^1.8",
16+
"friends-of-behat/mink-browserkit-driver": "^1.4",
17+
"friends-of-behat/mink-extension": "^2.4",
1718
"friends-of-behat/page-object-extension": "^0.3",
1819
"friends-of-behat/suite-settings-extension": "^1.0",
19-
"friends-of-behat/symfony-extension": "^2.0",
20-
"friends-of-behat/variadic-extension": "^1.1",
21-
"lakion/mink-debug-extension": "^1.2.3",
22-
"phpspec/phpspec": "^5.0",
23-
"phpstan/phpstan-doctrine": "^0.10",
24-
"phpstan/phpstan-shim": "^0.10",
25-
"phpstan/phpstan-symfony": "^0.10",
26-
"phpstan/phpstan-webmozart-assert": "^0.10",
27-
"sensiolabs/security-checker": "^5.0",
28-
"sylius-labs/coding-standard": "^2.0",
29-
"symfony/browser-kit": "^3.4|^4.1",
30-
"symfony/debug-bundle": "^3.4|^4.1",
31-
"symfony/dotenv": "^4.2",
32-
"symfony/intl": "^3.4|^4.1",
33-
"symfony/web-profiler-bundle": "^3.4|^4.1",
34-
"symfony/web-server-bundle": "^3.4|^4.1"
20+
"friends-of-behat/symfony-extension": "^2.1",
21+
"friends-of-behat/variadic-extension": "^1.3",
22+
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
23+
"lakion/mink-debug-extension": "^2.0.0",
24+
"phpspec/phpspec": "^7.0",
25+
"phpstan/extension-installer": "^1.0",
26+
"phpstan/phpstan": "0.12.82",
27+
"phpstan/phpstan-doctrine": "0.12.33",
28+
"phpstan/phpstan-strict-rules": "^0.12.0",
29+
"phpstan/phpstan-webmozart-assert": "0.12.12",
30+
"phpunit/phpunit": "^9.5",
31+
"sensiolabs/security-checker": "^6.0",
32+
"sylius-labs/coding-standard": "^3.1",
33+
"symfony/browser-kit": "^4.4 || ^5.2",
34+
"symfony/debug-bundle": "^4.4 || ^5.2",
35+
"symfony/dotenv": "^4.4 || ^5.2",
36+
"symfony/intl": "^4.4 || ^5.2",
37+
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
38+
"vimeo/psalm": "4.6.4"
3539
},
3640
"conflict": {
3741
"symfony/symfony": "4.1.8",

phpstan.neon

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
parameters:
2+
reportUnmatchedIgnoredErrors: false
3+
checkMissingIterableValueType: false
4+
5+
excludes_analyse:
6+
# Makes PHPStan crash
7+
- 'src/DependencyInjection/Configuration.php'
8+
9+
# Test dependencies
10+
- 'tests/Application/app/**.php'
11+
- 'tests/Application/src/**.php'
12+
13+
ignoreErrors:
14+
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'

psalm.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

spec/Event/ExportShipmentEventSpec.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
use Prophecy\Argument;
2020
use Sylius\Component\Core\Model\OrderInterface;
2121
use Sylius\Component\Core\Model\ShipmentInterface;
22-
use Symfony\Component\EventDispatcher\Event;
2322
use Symfony\Component\Filesystem\Filesystem;
2423
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
25-
use Symfony\Component\Translation\TranslatorInterface;
24+
use Symfony\Contracts\EventDispatcher\Event;
25+
use Symfony\Contracts\Translation\TranslatorInterface;
2626

2727
final class ExportShipmentEventSpec extends ObjectBehavior
2828
{

src/Event/ExportShipmentEvent.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
1616
use Doctrine\ORM\EntityManager;
1717
use Doctrine\ORM\EntityManagerInterface;
18-
use Symfony\Component\EventDispatcher\Event;
1918
use Symfony\Component\Filesystem\Filesystem;
2019
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
21-
use Symfony\Component\Translation\TranslatorInterface;
20+
use Symfony\Contracts\EventDispatcher\Event;
21+
use Symfony\Contracts\Translation\TranslatorInterface;
2222

2323
class ExportShipmentEvent extends Event
2424
{
25-
const NAME = 'bitbag.export_shipment';
25+
public const NAME = 'bitbag.export_shipment';
2626

2727
/** @var ShippingExportInterface */
2828
private $shippingExport;

src/Resources/config/services.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters:
22
bitbag.shipping_gateway.validation_groups: ['bitbag']
3-
bitbag.shipping_labels_path: "%kernel.root_dir%/../shipping_labels"
3+
bitbag.shipping_labels_path: '%kernel.project_dir%/shipping_labels'
44

55
services:
66
bitbag.shipping_export_plugin.menu.shipping_gateway:

tests/Application/.env

+6
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ DATABASE_URL=mysql://root@127.0.0.1/sylius_%kernel.environment%?serverVersion=5.
2121
# Delivery is disabled by default via "null://localhost"
2222
MAILER_URL=smtp://localhost
2323
###< symfony/swiftmailer-bundle ###
24+
25+
###> lexik/jwt-authentication-bundle ###
26+
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
27+
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
28+
JWT_PASSPHRASE=YOUR_SECRET_PASSPHRASE
29+
###< lexik/jwt-authentication-bundle ###

tests/Application/Kernel.php

+64-45
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@
55
namespace Tests\Acme\SyliusExamplePlugin\Application;
66

77
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
8+
use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel;
89
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
9-
use Symfony\Component\Config\Loader\DelegatingLoader;
1010
use Symfony\Component\Config\Loader\LoaderInterface;
11-
use Symfony\Component\Config\Loader\LoaderResolver;
1211
use Symfony\Component\Config\Resource\FileResource;
1312
use Symfony\Component\DependencyInjection\ContainerBuilder;
14-
use Symfony\Component\DependencyInjection\ContainerInterface;
15-
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
16-
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
17-
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
18-
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
19-
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
20-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
21-
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
22-
use Symfony\Component\HttpKernel\Config\FileLocator;
13+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
2314
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
2415
use Symfony\Component\Routing\RouteCollectionBuilder;
25-
use Webmozart\Assert\Assert;
2616

2717
final class Kernel extends BaseKernel
2818
{
@@ -42,33 +32,37 @@ public function getLogDir(): string
4232

4333
public function registerBundles(): iterable
4434
{
45-
$contents = require $this->getProjectDir() . '/config/bundles.php';
46-
foreach ($contents as $class => $envs) {
47-
if (isset($envs['all']) || isset($envs[$this->environment])) {
48-
yield new $class();
35+
foreach ($this->getConfigurationDirectories() as $confDir) {
36+
$bundlesFile = $confDir . '/bundles.php';
37+
if (false === is_file($bundlesFile)) {
38+
continue;
4939
}
40+
yield from $this->registerBundlesFromFile($bundlesFile);
5041
}
5142
}
5243

5344
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
5445
{
55-
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
46+
foreach ($this->getConfigurationDirectories() as $confDir) {
47+
$bundlesFile = $confDir . '/bundles.php';
48+
if (false === is_file($bundlesFile)) {
49+
continue;
50+
}
51+
$container->addResource(new FileResource($bundlesFile));
52+
}
53+
5654
$container->setParameter('container.dumper.inline_class_loader', true);
57-
$confDir = $this->getProjectDir() . '/config';
5855

59-
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
60-
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
61-
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
62-
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
56+
foreach ($this->getConfigurationDirectories() as $confDir) {
57+
$this->loadContainerConfiguration($loader, $confDir);
58+
}
6359
}
6460

6561
protected function configureRoutes(RouteCollectionBuilder $routes): void
6662
{
67-
$confDir = $this->getProjectDir() . '/config';
68-
69-
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
70-
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
71-
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
63+
foreach ($this->getConfigurationDirectories() as $confDir) {
64+
$this->loadRoutesConfiguration($routes, $confDir);
65+
}
7266
}
7367

7468
protected function getContainerBaseClass(): string
@@ -80,27 +74,52 @@ protected function getContainerBaseClass(): string
8074
return parent::getContainerBaseClass();
8175
}
8276

83-
protected function getContainerLoader(ContainerInterface $container): LoaderInterface
77+
private function isTestEnvironment(): bool
8478
{
85-
/** @var ContainerBuilder $container */
86-
Assert::isInstanceOf($container, ContainerBuilder::class);
87-
88-
$locator = new FileLocator($this, $this->getRootDir() . '/Resources');
89-
$resolver = new LoaderResolver([
90-
new XmlFileLoader($container, $locator),
91-
new YamlFileLoader($container, $locator),
92-
new IniFileLoader($container, $locator),
93-
new PhpFileLoader($container, $locator),
94-
new GlobFileLoader($container, $locator),
95-
new DirectoryLoader($container, $locator),
96-
new ClosureLoader($container),
97-
]);
98-
99-
return new DelegatingLoader($resolver);
79+
return 0 === strpos($this->getEnvironment(), 'test');
10080
}
10181

102-
private function isTestEnvironment(): bool
82+
private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void
10383
{
104-
return 0 === strpos($this->getEnvironment(), 'test');
84+
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
85+
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
86+
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
87+
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
88+
}
89+
90+
private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void
91+
{
92+
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
93+
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
94+
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
95+
}
96+
97+
/**
98+
* @return BundleInterface[]
99+
*/
100+
private function registerBundlesFromFile(string $bundlesFile): iterable
101+
{
102+
$contents = require $bundlesFile;
103+
foreach ($contents as $class => $envs) {
104+
if (isset($envs['all']) || isset($envs[$this->environment])) {
105+
yield new $class();
106+
}
107+
}
108+
}
109+
110+
/**
111+
* @return string[]
112+
*/
113+
private function getConfigurationDirectories(): iterable
114+
{
115+
yield $this->getProjectDir() . '/config';
116+
$syliusConfigDir = $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
117+
if (is_dir($syliusConfigDir)) {
118+
yield $syliusConfigDir;
119+
}
120+
$symfonyConfigDir = $this->getProjectDir() . '/config/symfony/' . BaseKernel::MAJOR_VERSION . '.' . BaseKernel::MINOR_VERSION;
121+
if (is_dir($symfonyConfigDir)) {
122+
yield $symfonyConfigDir;
123+
}
105124
}
106125
}

tests/Application/config/bootstrap.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Symfony\Component\Dotenv\Dotenv;
66

7-
require dirname(__DIR__) . '../../../vendor/autoload.php';
7+
require dirname(__DIR__).'../../../vendor/autoload.php';
88

99
// Load cached env vars if the .env.local.php file exists
1010
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
@@ -15,9 +15,9 @@
1515
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
1616
} else {
1717
// load all the .env files
18-
(new Dotenv())->loadEnv(dirname(__DIR__) . '/.env');
18+
(new Dotenv(true))->loadEnv(dirname(__DIR__) . '/.env');
1919
}
2020

2121
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
2222
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
23-
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
23+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

tests/Application/config/bundles.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
return [
64
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
75
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
86
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
97
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
108
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
119
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
12-
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
1310
Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true],
1411
Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true],
1512
Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true],
@@ -33,9 +30,7 @@
3330
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
3431
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
3532
winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true],
36-
Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true],
3733
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
38-
Sonata\IntlBundle\SonataIntlBundle::class => ['all' => true],
3934
Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true],
4035
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
4136
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
@@ -44,13 +39,10 @@
4439
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
4540
Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true],
4641
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
47-
WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true],
4842
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
49-
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true],
5043
Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true],
5144
Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true],
5245
Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true],
53-
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['all' => true],
5446
Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true],
5547
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
5648
FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
@@ -59,4 +51,10 @@
5951
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
6052
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
6153
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
54+
Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true],
55+
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
56+
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
57+
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
58+
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
59+
Symplify\ConsoleColorDiff\ConsoleColorDiffBundle::class => ['dev' => true, 'test' => true],
6260
];

0 commit comments

Comments
 (0)