Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for symfony 6 #31

Merged
merged 12 commits into from
Aug 24, 2022
40 changes: 28 additions & 12 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ jobs:
include:
- php-version: '7.3'
dependency-versions: 'lowest'
tools: 'composer:v1'
lint: false
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '7.4'
dependency-versions: 'highest'
tools: 'composer:v2'
lint: true
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.0'
dependency-versions: 'highest'
tools: 'composer:v2'
lint: true
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.1'
dependency-versions: 'highest'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

Expand All @@ -60,7 +59,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: 'imagick'
tools: ${{ matrix.tools }}
tools: 'composer:v2'

- name: Install composer dependencies
uses: ramsey/composer-install@v1
Expand All @@ -71,12 +70,29 @@ jobs:
run: composer bootstrap-test-environment
env: ${{ matrix.env }}

- name: Lint code
if: ${{ matrix.lint }}
run: composer lint
env: ${{ matrix.env }}

- name: Execute test cases
run: time composer test
env: ${{ matrix.env }}

lint:
name: 'PHP Lint'
runs-on: ubuntu-latest

steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: 'imagick'
tools: 'composer:v2'

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: ${{matrix.dependency-versions}}

- name: Lint code
run: composer lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/composer.phar
/composer.lock
.php_cs.cache
.php-cs-fixer.cache
*~

# IDEs
Expand Down
45 changes: 45 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

$header = <<<EOF
This file is part of Sulu.

(c) Sulu GmbH

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

$config = new PhpCsFixer\Config();
$config->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'class_definition' => false,
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'function_declaration' => ['closure_function_spacing' => 'none'],
'header_comment' => ['header' => $header],
'native_function_invocation' => ['include' => ['@internal']],
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true],
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_strict' => true,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_order' => true,
'phpdoc_to_comment' => false,
'phpdoc_types_order' => false,
'single_line_throw' => false,
'strict_comparison' => true,
'strict_param' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('node_modules')
->exclude('vendor')
->exclude('cache')
->exclude('Tests/Application/var/')
->exclude('Tests/reports/')
->in(__DIR__)
);

return $config;
28 changes: 0 additions & 28 deletions .php_cs.dist

This file was deleted.

13 changes: 6 additions & 7 deletions DependencyInjection/CompilerPass/ImageFormatCompilerPass.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
Expand All @@ -20,9 +22,6 @@
*/
class ImageFormatCompilerPass extends AbstractImageFormatCompilerPass
{
/**
* {@inheritdoc}
*/
protected function getFiles(ContainerBuilder $container)
{
/** @var ThemeRepositoryInterface $themeRepository */
Expand All @@ -35,22 +34,22 @@ protected function getFiles(ContainerBuilder $container)

$files = [];
foreach ($themeRepository->findAll() as $theme) {
foreach ($bundles as $bundleName => $bundle) {
foreach ($bundles as $bundle) {
$bundleReflection = new \ReflectionClass($bundle);
$fileName = $bundleReflection->getFileName();

if (!$fileName) {
continue;
}

$path = sprintf(
$path = \sprintf(
'%s/Resources/themes/%s/%s',
dirname($fileName),
\dirname($fileName),
$theme->getName(),
$configPath
);

if (file_exists($path)) {
if (\file_exists($path)) {
$files[] = $path;
}
}
Expand Down
7 changes: 3 additions & 4 deletions DependencyInjection/SuluThemeExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
Expand All @@ -23,16 +25,13 @@
*/
class SuluThemeExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

/** @var string $context */
$context = $container->getParameter('sulu.context');

$loader->load(sprintf('%s.xml', $context));
$loader->load(\sprintf('%s.xml', $context));
}
}
8 changes: 7 additions & 1 deletion EventListener/SetThemeEventListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
Expand All @@ -12,6 +14,7 @@
namespace Sulu\Bundle\ThemeBundle\EventListener;

use Sulu\Bundle\PreviewBundle\Preview\Events\PreRenderEvent;
use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes;
use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
Expand Down Expand Up @@ -42,7 +45,10 @@ public function __construct(ThemeRepositoryInterface $themeRepository, SettableT
*/
public function setActiveThemeOnRequest(RequestEvent $event): void
{
if (null === ($attributes = $event->getRequest()->get('_sulu'))
/** @var ?RequestAttributes $attributes */
$attributes = $event->getRequest()->get('_sulu');

if (null === $attributes
|| null === ($webspace = $attributes->getAttribute('webspace'))
|| null === ($theme = $webspace->getTheme())
) {
Expand Down
2 changes: 2 additions & 0 deletions SuluThemeBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
Expand Down
2 changes: 1 addition & 1 deletion Tests/Application/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_ENV=test
DATABASE_URL=mysql://root:@127.0.0.1:3306/su_theme_test
DATABASE_URL=mysql://root:@127.0.0.1:3306/su_theme_test?serverVersion=5.7.22
DATABASE_CHARSET=utf8mb4
DATABASE_COLLATE=utf8mb4_unicode_ci
17 changes: 5 additions & 12 deletions Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
Expand All @@ -18,20 +20,14 @@

class Kernel extends SuluTestKernel
{
/**
* {@inheritdoc}
*/
public function __construct($environment, $debug, $suluContext = self::CONTEXT_ADMIN)
{
parent::__construct($environment, $debug, $suluContext);
}

/**
* {@inheritdoc}
*/
public function registerBundles()
public function registerBundles(): iterable
{
return array_merge(
return \array_merge(
parent::registerBundles(),
[
new SyliusThemeBundle(),
Expand All @@ -40,17 +36,14 @@ public function registerBundles()
);
}

/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

$loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yaml');
}

protected function getKernelParameters()
protected function getKernelParameters(): array
{
$parameters = parent::getKernelParameters();

Expand Down
10 changes: 5 additions & 5 deletions Tests/Application/bin/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// umask(0000);

set_time_limit(0);
\set_time_limit(0);

require_once __DIR__ . '/../config/bootstrap.php';

Expand All @@ -25,12 +25,12 @@
use Symfony\Component\ErrorHandler\Debug;

$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = '0' !== getenv('SYMFONY_DEBUG') && !$input->hasParameterOption(['--no-debug', '']) && 'prod' !== $env;
$env = $input->getParameterOption(['--env', '-e'], \getenv('SYMFONY_ENV') ?: 'dev');
$debug = '0' !== \getenv('SYMFONY_DEBUG') && !$input->hasParameterOption(['--no-debug', '']) && 'prod' !== $env;

if ($debug) {
// Clean up when sf 4.3 support is removed
if (class_exists(Debug::class)) {
if (\class_exists(Debug::class)) {
Debug::enable();
} else {
\Symfony\Component\Debug\Debug::enable();
Expand Down
10 changes: 5 additions & 5 deletions Tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@

$file = __DIR__ . '/../../../vendor/autoload.php';

if (!file_exists($file)) {
if (!\file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}

require $file;

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) {
if (\is_array($env = @include \dirname(__DIR__) . '/.env.local.php')) {
$_SERVER += $env;
$_ENV += $env;
} elseif (!class_exists(Dotenv::class)) {
} elseif (!\class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
$path = dirname(__DIR__) . '/.env';
$path = \dirname(__DIR__) . '/.env';
$dotenv = new Dotenv();
$dotenv->loadEnv($path);
}

$_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';
Loading