Skip to content

Commit

Permalink
added support for Symfony 6, dropped support for Symfony 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Jan 14, 2022
1 parent ee83282 commit ed7f6ad
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 103 deletions.
25 changes: 11 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,28 @@ jobs:
include:
- stage: smoke test 🕵️
php: 7.3
env: DEPS='lowest' WITH_DOCTRINE_CACHE_BUNDLE='yes' SYMFONY_DEPRECATIONS_HELPER='max[self]=2&max[direct]=168&max[indirect]=871'
env: DEPS='lowest' WITH_DOCTRINE_CACHE_BUNDLE='yes' SYMFONY_DEPRECATIONS_HELPER='max[self]=2&max[indirect]=1230'
-
php: 8.0
env: DEPS='unmodified' WITH_STATIC_ANALYSIS='yes'
php: 8.1.0
env: DEPS='unmodified' WITH_STATIC_ANALYSIS='yes' SYMFONY_DEPRECATIONS_HELPER='max[indirect]=1'

- stage: test
php: 7.3
env: SYMFONY_VERSION='3.4.*' WITH_DOCTRINE_CACHE_BUNDLE='yes' SYMFONY_DEPRECATIONS_HELPER='max[indirect]=4'
-
php: 7.4
env: SYMFONY_VERSION='3.4.*' WITH_DOCTRINE_CACHE_BUNDLE='yes' SYMFONY_DEPRECATIONS_HELPER='max[indirect]=4'
-
php: 7.3
env: SYMFONY_VERSION='4.4.*' WITH_DOCTRINE_CACHE_BUNDLE='yes' SYMFONY_DEPRECATIONS_HELPER='max[indirect]=4'
env: SYMFONY_VERSION='4.4.*' WITH_DOCTRINE_CACHE_BUNDLE='yes' SYMFONY_DEPRECATIONS_HELPER='max[indirect]=3'
-
php: 7.4
env: SYMFONY_VERSION='5.3.*'
-
php: 7.4
env: SYMFONY_VERSION='5.4.*' MIN_STABILITY='dev'
php: 8.0
env: SYMFONY_VERSION='5.4.*'
-
php: 8.0
env: SYMFONY_VERSION='5.4.*' MIN_STABILITY='dev'
env: SYMFONY_VERSION='6.0.*'
-
php: 8.1.0
env: SYMFONY_VERSION='6.1.*' MIN_STABILITY='dev'
allow_failures:
- env: SYMFONY_VERSION='5.4.*' MIN_STABILITY='dev'
- env: SYMFONY_VERSION='6.1.*' MIN_STABILITY='dev'
fast_finish: true

install:
Expand Down
2 changes: 1 addition & 1 deletion .travis_install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [ -n "${WITH_STATIC_ANALYSIS:-}" ]; then
fi

if [ -n "${WITH_DOCTRINE_CACHE_BUNDLE:-}" ]; then
composer require --no-update --dev "doctrine/doctrine-cache-bundle:^1.3.5"
composer require --no-update --dev "doctrine/doctrine-cache-bundle:^1.3.1"
fi

composer update ${COMPOSER_UPDATE_ARGS:-} --with-all-dependencies
Expand Down
11 changes: 0 additions & 11 deletions CacheAdapter/DoctrineCacheBundleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ public function set($key, $value) {
}

public function setMultiple(array $keysAndValues) {
// TODO remove as soon as doctrine/cache >= 1.6 is required
if (!method_exists($this->cache, 'saveMultiple')) {
foreach ($keysAndValues as $key => $value) {
if (!$this->cache->save($key, $value)) {
return false;
}
}

return true;
}

return $this->cache->saveMultiple($keysAndValues);
}

Expand Down
7 changes: 0 additions & 7 deletions CacheAdapter/SymfonyCacheComponentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Psr\Cache\CacheItemPoolInterface;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\Adapter\Psr16Adapter;
use Symfony\Component\Cache\Adapter\SimpleCacheAdapter;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -28,12 +27,6 @@ public function __construct($cache) {
if ($cache instanceof CacheInterface) {
@trigger_error(sprintf('Configuring a cache of type %s is deprecated since CraueConfigBundle 2.2.1. Use %s instead.', CacheInterface::class, CacheItemPoolInterface::class), E_USER_DEPRECATED);

// TODO remove as soon as Symfony >= 4.3 is required
if (!class_exists('Symfony\Component\Cache\Adapter\Psr16Adapter')) {
$this->cache = new SimpleCacheAdapter($cache);
return;
}

$this->cache = new Psr16Adapter($cache);
return;
}
Expand Down
9 changes: 5 additions & 4 deletions Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use Craue\ConfigBundle\CacheAdapter\CacheAdapterInterface;
use Craue\ConfigBundle\Entity\SettingInterface;
use Craue\ConfigBundle\Form\ModifySettingsForm;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

/**
Expand All @@ -21,8 +23,7 @@
class SettingsController extends AbstractController {

public function modifyAction(CacheAdapterInterface $cache, FormFactoryInterface $formFactory, Request $request,
SessionInterface $session, Environment $twig) {
$em = $this->getDoctrine()->getManager();
SessionInterface $session, Environment $twig, EntityManagerInterface $em, TranslatorInterface $translator) {
$repo = $em->getRepository($this->container->getParameter('craue_config.entity_name'));
$allStoredSettings = $repo->findAll();

Expand All @@ -47,10 +48,10 @@ public function modifyAction(CacheAdapterInterface $cache, FormFactoryInterface
$em->flush();

if ($session instanceof Session) {
$session->getFlashBag()->set('notice', $this->get('translator')->trans('settings_changed', [], 'CraueConfigBundle'));
$session->getFlashBag()->set('notice', $translator->trans('settings_changed', [], 'CraueConfigBundle'));
}

return $this->redirect($this->generateUrl($this->container->getParameter('craue_config.redirectRouteAfterModify')));
return $this->redirectToRoute($this->container->getParameter('craue_config.redirectRouteAfterModify'));
}
}

Expand Down
9 changes: 1 addition & 8 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ public function getConfigTreeBuilder() : TreeBuilder {

$treeBuilder = new TreeBuilder('craue_config');

if (!method_exists($treeBuilder, 'getRootNode')) {
// TODO remove as soon as Symfony >= 4.2 is required
$rootNode = $treeBuilder->root('craue_config');
} else {
$rootNode = $treeBuilder->getRootNode();
}

$rootNode
$treeBuilder->getRootNode()
->children()
->enumNode('db_driver')
->values($supportedDrivers)
Expand Down
20 changes: 0 additions & 20 deletions Tests/CacheAdapter/DoctrineCacheBundleAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,4 @@ protected function getAdapter() {
return new DoctrineCacheBundleAdapter(new ArrayCache());
}

/**
* TODO remove as soon as doctrine/cache >= 1.6 is required
*/
public function testSetMultiple_fails() {
if (method_exists(ArrayCache::class, 'saveMultiple')) {
$this->markTestSkipped('DoctrineCacheBundle already supports `saveMultiple`.');
}

$providerMock = $this->createMock(ArrayCache::class);

$providerMock->expects($this->once())
->method('save')
->will($this->returnValue(false))
;

$adapter = new DoctrineCacheBundleAdapter($providerMock);

$this->assertFalse($adapter->setMultiple(['key' => 'value']));
}

}
2 changes: 1 addition & 1 deletion Tests/IntegrationTestBundle/Controller/DebugController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DebugController extends AbstractController {

public function getAction($name) {
return new JsonResponse([
$name => $this->get('craue_config')->get($name),
$name => $this->container->get('craue_config')->get($name),
]);
}

Expand Down
10 changes: 4 additions & 6 deletions Tests/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Craue\ConfigBundle\Util\Config;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\HttpKernel\KernelInterface;
Expand All @@ -21,8 +20,7 @@
abstract class IntegrationTestCase extends WebTestCase {

/**
* @var AbstractBrowser|Client|null
* TODO remove Client type as soon as Symfony >= 4.3 is required
* @var AbstractBrowser|null
*/
protected static $client;

Expand Down Expand Up @@ -171,12 +169,12 @@ protected function getTwig() {
* @return object The associated service.
*/
protected function getService($id) {
// TODO remove as soon as Symfony >= 4.3 is required
if (!property_exists($this, 'container')) {
// TODO remove as soon as Symfony >= 5.3 is required
if (!method_exists($this, 'getContainer')) {
return static::$kernel->getContainer()->get($id);
}

return self::$container->get($id);
return static::getContainer()->get($id);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/config/config_cache_SymfonyCacheComponent_redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
class: \Redis
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
arguments:
- '%REDIS_DSN%'
- '%env(REDIS_DSN)%'
craue_config_cache_provider:
class: Symfony\Component\Cache\Adapter\RedisAdapter
public: false
Expand Down
5 changes: 0 additions & 5 deletions Tests/config/config_hacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
]);
}

// TODO in config_cache_SymfonyCacheComponent_redis.yml, replace '%REDIS_DSN%' by '%env(REDIS_DSN)%' as soon as Symfony >= 4.0 is required (and remove this hack)
if (!empty($_ENV['REDIS_DSN'])) {
$container->setParameter('REDIS_DSN', $_ENV['REDIS_DSN']);
}

// TODO put back into config.yml as soon as Symfony >= 5.3 is required, see https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.3.md#frameworkbundle
$container->loadFromExtension('framework', [
'session' => Kernel::VERSION_ID >= 50300 ? [
Expand Down
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
],
"require": {
"php": "^7.3|^8",
"doctrine/doctrine-bundle": "^1.5.1|~2.0",
"doctrine/doctrine-bundle": "^1.6.12|~2.0",
"psr/simple-cache": "^1.0",
"symfony/cache": "~3.4|~4.4|~5.3",
"symfony/config": "~3.4|~4.4|~5.3",
"symfony/dependency-injection": "~3.4|~4.4|~5.3",
"symfony/form": "~3.4|~4.4|~5.3",
"symfony/framework-bundle": "~3.4|~4.4|~5.3",
"symfony/http-foundation": "~3.4|~4.4|~5.3",
"symfony/http-kernel": "~3.4|~4.4|~5.3",
"symfony/options-resolver": "~3.4|~4.4|~5.3",
"symfony/validator": "~3.4|~4.4|~5.3"
"symfony/cache": "~4.4|~5.3|^6.0",
"symfony/config": "~4.4|~5.3|^6.0",
"symfony/dependency-injection": "~4.4|~5.3|^6.0",
"symfony/form": "~4.4|~5.3|^6.0",
"symfony/framework-bundle": "~4.4|~5.3|^6.0",
"symfony/http-foundation": "~4.4|~5.3|^6.0",
"symfony/http-kernel": "~4.4|~5.3|^6.0",
"symfony/options-resolver": "~4.4|~5.3|^6.0",
"symfony/validator": "~4.4|~5.3|^6.0"
},
"require-dev": {
"craue/translations-tests": "^1.0",
"doctrine/instantiator": "^1.0.5",
"doctrine/orm": "^2.5.14",
"phpunit/phpunit": "^9.5",
"symfony/asset": "~3.4|~4.4|~5.3",
"symfony/browser-kit": "~3.4|~4.4|~5.3",
"symfony/phpunit-bridge": "~5.3",
"symfony/twig-bundle": "~3.4|~4.4|~5.3",
"symfony/web-profiler-bundle": "~3.4|~4.4|~5.3"
"symfony/asset": "~4.4|~5.3|^6.0",
"symfony/browser-kit": "~4.4|~5.3|^6.0",
"symfony/phpunit-bridge": "^6.0",
"symfony/twig-bundle": "~4.4|~5.3|^6.0",
"symfony/web-profiler-bundle": "~4.4|~5.3|^6.0"
},
"minimum-stability": "stable",
"autoload": {
Expand All @@ -54,7 +54,7 @@
"dev-master": "2.6.x-dev"
},
"symfony": {
"require": "~3.4.23|~4.4|~5.3"
"require": "~4.4|~5.3|^6.0"
}
},
"config": {
Expand Down
10 changes: 1 addition & 9 deletions phpstan-config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ parameters:
- vendor/*
ignoreErrors:
- '#^Call to an undefined method Psr\\Container\\ContainerInterface::getParameter\(\)\.$#'
- '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)\.$#'
- '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.$#'
-
message: '#^Unsafe usage of new static\(\)\.$#'
path: Entity/BaseSetting.php
# TODO remove as soon as Symfony >= 4.3 is required
-
message: '#^Instantiated class Symfony\\Component\\Cache\\Adapter\\SimpleCacheAdapter not found\.$#'
path: CacheAdapter/SymfonyCacheComponentAdapter.php
# TODO remove as soon as Symfony >= 4.3 is required
-
message: '#^Property Craue\\ConfigBundle\\CacheAdapter\\SymfonyCacheComponentAdapter::\$cache \(Psr\\Cache\\CacheItemPoolInterface\) does not accept Symfony\\Component\\Cache\\Adapter\\SimpleCacheAdapter\.$#'
path: CacheAdapter/SymfonyCacheComponentAdapter.php

0 comments on commit ed7f6ad

Please sign in to comment.