Skip to content

Commit

Permalink
Adjust for sf7 and new doctrine versions
Browse files Browse the repository at this point in the history
* drop annotations
* adjust security to symfony 7
* ignore database creation failure because doctrine dbal decided to be a stickler
* drop symfony 5 support
  • Loading branch information
dbu committed Feb 19, 2024
1 parent 03456ab commit 54baa29
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 262 deletions.
42 changes: 14 additions & 28 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,22 @@ jobs:
runs-on: ubuntu-20.04

env:
SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.symfony-deprecation-helper }}
SYMFONY_DEPRECATIONS_HELPER: weak
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}

strategy:
fail-fast: false
matrix:
symfony-version:
- '*'
include:
- php-version: '7.1'
dependencies: 'lowest'
symfony-version: '^3.4'
symfony-deprecation-helper: 'weak'

- php-version: '7.2'
- php-version: '7.3'
- php-version: '7.4'
symfony-version: '^4.4'
- php-version: '7.4'
symfony-version: '5.0.*'
- php-version: '8.0'
- php-version: '8.0'
symfony-version: '6.0.*'
- php-version: '8.2'
symfony-version: '7.0.*'
fail-fast: false
matrix:
include:
- php-version: '8.1'
dependencies: 'lowest'
- php-version: '8.1'
- php-version: '8.2'
- php-version: '8.3'

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
Expand All @@ -52,13 +39,12 @@ jobs:
tools: 'composer:v2'

- name: Install Symfony Flex
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex

- name: Allow Symfony Flex Plugin
run: composer global config --no-plugins allow-plugins.symfony/flex true
run: |
composer global require --no-progress --no-scripts --no-plugins symfony/flex
composer global config --no-plugins allow-plugins.symfony/flex true
- name: Install dependencies with Composer
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: --prefer-dist
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

5.0.0 (unreleased)

* Support Symfony 7, drop support for Symfony < 6.4
* The default framework configuration no longer enables validation attributes.
* The phpcr-odm additional namespace is expected to use attributes rather than annotations.

4.4.2
-----

Expand Down
2 changes: 1 addition & 1 deletion bin/make/functional_tests_orm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ functional_tests_orm:
@echo
@echo '+++ create ORM database +++'
@${CONSOLE} doctrine:schema:drop --env=orm --force
@${CONSOLE} doctrine:database:create --env=orm
@${CONSOLE} doctrine:database:create --env=orm || echo "Failed to create database. If this is sqlite, this is normal. Otherwise there will be an error with schema creation"
@${CONSOLE} doctrine:schema:create --env=orm
@echo '+++ run ORM functional tests +++'
ifeq ($(HAS_XDEBUG), 0)
Expand Down
18 changes: 0 additions & 18 deletions bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@
exit(1);
}

use Doctrine\Common\Annotations\AnnotationRegistry;

if (method_exists(AnnotationRegistry::class, 'registerLoader')) {
AnnotationRegistry::registerLoader(function ($class) use ($loader) {
$loader->loadClass($class);

// this was class_exists($class, false) i.e. do not autoload.
// this is required so that custom annotations (e.g. TreeUiBundle
// annotations) are autoloaded - but they should be found by the
// composer loader above.
//
// This probably slows things down.
//
// @todo: Fix me.
return class_exists($class);
});
}

if (!defined('CMF_TEST_ROOT_DIR')) {
define('CMF_TEST_ROOT_DIR', realpath(__DIR__.'/..'));
}
Expand Down
25 changes: 14 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
}
],
"require": {
"php": "^7.1|^8.0",
"php": "^8.1",
"doctrine/data-fixtures": "^1.2",
"symfony/browser-kit": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0"
"symfony/browser-kit": "^6.4 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/phpcr-bundle": "^1.3 || ^2.0.0 || ^3.0@beta",
"symfony/console": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"symfony/doctrine-bridge": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"symfony/http-kernel": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"doctrine/phpcr-bundle": "^3.0@beta",
"symfony/console": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/monolog-bundle": "^3.5",
"symfony/security-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"symfony/twig-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^5.4"
"symfony/security-bundle": "^6.4 || ^7.0",
"symfony/twig-bundle": "^6.4 || ^7.0",
"symfony/phpunit-bridge": "^7.0.3"
},
"conflict": {
"doctrine/phpcr-bundle": "<3.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>

</phpunit>
23 changes: 0 additions & 23 deletions resources/.travis.yml

This file was deleted.

19 changes: 4 additions & 15 deletions resources/config/dist/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,25 @@
* file that was distributed with this source code.
*/

$routerPath = '%kernel.root_dir%/config/routing.php';
if ($container->hasParameter('kernel.project_dir')) {
$routerPath = '%kernel.project_dir%/config/routing.php';
}

$config = [
'secret' => 'test',
'test' => null,
'form' => true,
'validation' => [
'enabled' => true,
'enable_annotations' => true,
],
'router' => [
'resource' => $routerPath,
'resource' => '%kernel.project_dir%/config/routing.php',
],
'default_locale' => 'en',
'translator' => [
'fallback' => 'en',
],
'session' => [
'storage_factory_id' => 'session.storage.factory.mock_file',
],
];

if (interface_exists(\Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface::class)) {
// Symfony 5.3+
$config = array_merge($config, ['session' => ['storage_factory_id' => 'session.storage.factory.mock_file']]);
} else {
// Symfony <5.3
$config = array_merge($config, ['session' => ['storage_id' => 'session.storage.filesystem']]);
}

$container->loadFromExtension('framework', $config);

$container->loadFromExtension('twig', [
Expand Down
2 changes: 1 addition & 1 deletion resources/config/dist/phpcr_odm.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

if (file_exists($phpcrOdmDocDir)) {
$config['odm']['mappings']['test_additional'] = [
'type' => 'annotation',
'type' => 'attribute',
'prefix' => $phpcrOdmDocPrefix,
'dir' => $phpcrOdmDocDir,
'is_bundle' => false,
Expand Down
11 changes: 1 addition & 10 deletions resources/config/dist/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
*/

$config = [
'encoders' => [
'Symfony\Component\Security\Core\User\User' => 'plaintext',
],
'role_hierarchy' => [
'ROLE_ADMIN' => 'ROLE_USER',
'ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'],
Expand Down Expand Up @@ -40,13 +37,7 @@
],
];

if (class_exists(\Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider::class)) {
// Symfony <=5.4
$config = array_merge($config, ['firewall' => ['main' => ['anonymous' => null]]]);
}

if (interface_exists(\Symfony\Component\PasswordHasher\PasswordHasherInterface::class)) {
unset($config['encoders']);
if (class_exists(\Symfony\Component\Security\Core\Security::class)) {
$config = array_merge($config, [
'enable_authenticator_manager' => true,
'password_hashers' => ['Symfony\Component\Security\Core\User\User' => 'plaintext'],
Expand Down
36 changes: 6 additions & 30 deletions src/Functional/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
namespace Symfony\Cmf\Component\Testing\Functional;

use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Cmf\Component\Testing\Functional\DbManager\ORM;
use Symfony\Cmf\Component\Testing\Functional\DbManager\PHPCR;
use Symfony\Cmf\Component\Testing\Functional\DbManager\PhpcrDecorator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;

Expand All @@ -32,15 +30,10 @@ abstract class BaseTestCase extends WebTestCase
{
/**
* Use this property to save the DbManagers.
*
* @var array
*/
protected $dbManagers = [];
protected array $dbManagers = [];

/**
* @var Client
*/
protected $client;
protected ?KernelBrowser $client = null;

/**
* Return the configuration to use when creating the Kernel.
Expand Down Expand Up @@ -80,18 +73,6 @@ protected static function bootKernel(array $options = []): KernelInterface
return parent::bootKernel(static::getKernelConfiguration());
}

/**
* BC with Symfony < 5.3 - when minimum version raises to ^5.3, we can remove this method.
*/
protected static function getContainer(): ContainerInterface
{
if (method_exists(KernelTestCase::class, 'getContainer')) {
return parent::getContainer();
}

return self::getKernel()->getContainer();
}

protected static function getKernel(): KernelInterface
{
if (null === static::$kernel) {
Expand All @@ -100,9 +81,7 @@ protected static function getKernel(): KernelInterface

if (static::$kernel instanceof KernelInterface) {
$kernelEnvironment = static::$kernel->getEnvironment();
$expectedEnvironment = isset(static::getKernelConfiguration()['environment'])
? static::getKernelConfiguration()['environment']
: 'phpcr';
$expectedEnvironment = static::getKernelConfiguration()['environment'] ?? 'phpcr';
if ($kernelEnvironment !== $expectedEnvironment) {
var_dump($kernelEnvironment, $expectedEnvironment);
static::bootKernel();
Expand All @@ -116,17 +95,14 @@ protected static function getKernel(): KernelInterface
return static::$kernel;
}

/**
* @return Client|KernelBrowser
*/
protected function getFrameworkBundleClient()
protected function getFrameworkBundleClient(): KernelBrowser
{
if (null === $this->client) {
// property does not exist in all symfony versions
if (property_exists(self::class, 'booted') && self::$booted) {
self::ensureKernelShutdown();
}
$this->client = self::createClient($this->getKernelConfiguration());
$this->client = self::createClient(self::getKernelConfiguration());
}

return $this->client;
Expand Down Expand Up @@ -174,7 +150,7 @@ protected function getDbManager(string $type)
return $dbManager;
}

protected static function assertResponseSuccess(Response $response)
protected static function assertResponseSuccess(Response $response): void
{
libxml_use_internal_errors(true);

Expand Down
Loading

0 comments on commit 54baa29

Please sign in to comment.