Skip to content

Commit

Permalink
Add support for Sylius 1.9 and multiple Sylius version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Mar 3, 2021
1 parent f9c4104 commit 69cea02
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 117 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ on:
schedule:
-
cron: "0 1 * * 6" # Run at 1am every Saturday
workflow_dispatch: ~

jobs:
tests:
runs-on: ubuntu-latest

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]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0]
node: [10.x]
mysql: [5.7, 8.0]
mysql: [5.7]

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 @@ -90,6 +93,16 @@ jobs:
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
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
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"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": "^2.0.0",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.1",
Expand All @@ -29,11 +30,11 @@
"phpunit/phpunit": "^9.5",
"sensiolabs/security-checker": "^6.0",
"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/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.3"
},
"prefer-stable": true,
Expand All @@ -60,7 +61,6 @@
"scripts": {
"analyse": [
"@composer validate --strict",
"vendor/bin/ecs check .",
"vendor/bin/phpstan.phar analyse -c phpstan.neon -l max src/",
"vendor/bin/psalm"
],
Expand Down
15 changes: 7 additions & 8 deletions tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ 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://[email protected]/sylius_%kernel.environment%?serverVersion=5.5
DATABASE_URL=mysql://[email protected]/sylius_%kernel.environment%?serverVersion=5.7
###< doctrine/doctrine-bundle ###

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=smtp://localhost
###< symfony/swiftmailer-bundle ###

###> lexik/jwt-authentication-bundle ###
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=acme_plugin_development
###< lexik/jwt-authentication-bundle ###

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=smtp://localhost
###< symfony/swiftmailer-bundle ###
1 change: 0 additions & 1 deletion tests/Application/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
!/public/media/image/
/public/media/image/*
!/public/media/image/.gitignore
yarn.lock

/node_modules

Expand Down
112 changes: 46 additions & 66 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,58 @@
namespace Tests\Prometee\SyliusPayumMoneticoPlugin\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;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Webmozart\Assert\Assert;

final class Kernel extends BaseKernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{php,xml,yaml,yml}';

/**
* {@inheritdoc}
*/
public function getCacheDir(): string
{
return $this->getProjectDir() . '/var/cache/' . $this->environment;
}

/**
* {@inheritdoc}
*/
public function getLogDir(): string
{
return $this->getProjectDir() . '/var/log';
}

/**
* {@inheritdoc}
*/
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
foreach ($this->getConfigurationDirectories() as $confDir) {
yield from $this->registerBundlesFromFile($confDir . '/bundles.php');
}
}

/**
* {@inheritdoc}
*/
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);
}
}

/**
* {@inheritdoc}
*/
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);
}
}

/**
* {@inheritdoc}
*/
protected function getContainerBaseClass(): string
{
if ($this->isTestEnvironment()) {
Expand All @@ -98,33 +66,45 @@ protected function getContainerBaseClass(): string
return parent::getContainerBaseClass();
}

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');
}

/**
* {@inheritdoc}
* @return BundleInterface[]
*/
protected function getContainerLoader(ContainerInterface $container): LoaderInterface
private function registerBundlesFromFile(string $bundlesFile): iterable
{
/** @var ContainerBuilder $container */
Assert::isInstanceOf($container, ContainerBuilder::class);

$locator = new FileLocator($this, $this->getProjectDir() . '/Resources');
$resolver = new LoaderResolver(array(
new XmlFileLoader($container, $locator),
new YamlFileLoader($container, $locator),
new IniFileLoader($container, $locator),
new PhpFileLoader($container, $locator),
new GlobFileLoader($container, $locator),
new DirectoryLoader($container, $locator),
new ClosureLoader($container),
));

return new DelegatingLoader($resolver);
$contents = require $bundlesFile;
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}

/**
* @return bool
* @return string[]
*/
private function isTestEnvironment(): bool
private function getConfigurationDirectories(): iterable
{
return 0 === strpos($this->getEnvironment(), 'test');
yield $this->getProjectDir() . '/config';
yield $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
}
}
2 changes: 1 addition & 1 deletion tests/Application/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Tests\Prometee\SyliusPayumMoneticoPlugin\Application\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\ErrorHandler\Debug;

set_time_limit(0);

Expand Down
18 changes: 0 additions & 18 deletions tests/Application/composer.lock

This file was deleted.

4 changes: 3 additions & 1 deletion tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'../../../vendor/autoload.php';
Expand All @@ -18,4 +20,4 @@

$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
5 changes: 2 additions & 3 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,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],
Expand All @@ -52,9 +50,10 @@
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
Symplify\ConsoleColorDiff\ConsoleColorDiffBundle::class => ['dev' => true, 'test' => true],
Prometee\SyliusPayumMoneticoPlugin\PrometeeSyliusPayumMoneticoPlugin::class => ['all' => true],
Expand Down
2 changes: 0 additions & 2 deletions tests/Application/config/packages/fos_rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ fos_rest:
json: true
xml: true
empty_content: 204
zone:
- { path: '^/api/.*' }
format_listener:
rules:
- { path: '^/api/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
Expand Down
1 change: 0 additions & 1 deletion tests/Application/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ framework:
secret: '%env(APP_SECRET)%'
form: true
csrf_protection: true
templating: { engines: ["twig"] }
session:
handler_id: ~
2 changes: 1 addition & 1 deletion tests/Application/config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ imports:
# workaround needed for strange "test.client.history" problem
# see https://github.com/FriendsOfBehat/SymfonyExtension/issues/88
services:
Symfony\Component\BrowserKit\AbstractBrowser: '@test.client'
Symfony\Component\BrowserKit\AbstractBrowser: '@test.client'
6 changes: 6 additions & 0 deletions tests/Application/config/sylius/1.8/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true],
];
2 changes: 2 additions & 0 deletions tests/Application/config/sylius/1.8/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
templating: { engines: ["twig"] }
6 changes: 6 additions & 0 deletions tests/Application/config/sylius/1.9/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
];
Loading

0 comments on commit 69cea02

Please sign in to comment.