Skip to content

Commit 76d955d

Browse files
committed
⬆️ Symfony 6 support, upgrade and improve code for deprecations
1 parent 501bc43 commit 76d955d

File tree

8 files changed

+55
-70
lines changed

8 files changed

+55
-70
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
strategy:
1515
matrix:
1616
php-version:
17-
- "7.4"
1817
- "8.0"
1918

2019
services:
@@ -28,7 +27,7 @@ jobs:
2827

2928
steps:
3029
- name: "Checkout"
31-
uses: "actions/checkout@v2"
30+
uses: "actions/checkout@v4"
3231
with:
3332
fetch-depth: 2
3433

@@ -41,14 +40,14 @@ jobs:
4140
tools: "cs2pr"
4241

4342
- name: "Cache dependencies installed with composer"
44-
uses: "actions/cache@v1"
43+
uses: "actions/cache@v4"
4544
with:
4645
path: "~/.composer/cache"
4746
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
4847
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
4948

5049
- name: "Install dependencies with composer"
51-
run: "composer install --no-interaction --no-progress --no-suggest"
50+
run: "composer install --no-interaction --no-progress"
5251

5352
- name: "Run PHPUnit"
5453
run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml"
@@ -67,7 +66,6 @@ jobs:
6766
strategy:
6867
matrix:
6968
php-version:
70-
- "7.4"
7169
- "8.0"
7270

7371
services:
@@ -81,7 +79,7 @@ jobs:
8179

8280
steps:
8381
- name: "Checkout"
84-
uses: "actions/checkout@v2"
82+
uses: "actions/checkout@v4"
8583
with:
8684
fetch-depth: 2
8785

@@ -93,14 +91,14 @@ jobs:
9391
coverage: "pcov"
9492

9593
- name: "Cache dependencies installed with composer"
96-
uses: "actions/cache@v1"
94+
uses: "actions/cache@v4"
9795
with:
9896
path: "~/.composer/cache"
9997
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
10098
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
10199

102100
- name: "Install dependencies with composer"
103-
run: "composer update --no-interaction --no-progress --no-suggest --prefer-lowest"
101+
run: "composer update --no-interaction --no-progress --prefer-lowest"
104102

105103
- name: "Run PHPUnit"
106104
run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml"

DependencyInjection/Configuration.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,43 @@
33

44
namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;
55

6+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
67
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
78
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
89
use Symfony\Component\Config\Definition\ConfigurationInterface;
910

1011
class Configuration implements ConfigurationInterface
1112
{
12-
public function getConfigTreeBuilder()
13+
public function getConfigTreeBuilder(): TreeBuilder
1314
{
1415
$treeBuilder = new TreeBuilder('tdbm');
1516
$rootNode = $treeBuilder->getRootNode();
17+
assert($rootNode instanceof ArrayNodeDefinition);
1618

1719
$rootNodeChildren = $rootNode->children();
18-
1920
$this->buildServiceNode($rootNodeChildren);
2021

21-
$rootNodeServices = $rootNodeChildren->arrayNode('databases')->arrayPrototype()->children();
22-
$this->buildServiceNode($rootNodeServices);
23-
$rootNodeServices->end()->end()->end();
24-
25-
$rootNodeChildren->end();
22+
$rootNodeDatabases = $rootNodeChildren->arrayNode('databases')->arrayPrototype()->children();
23+
$this->buildServiceNode($rootNodeDatabases);
2624

2725
return $treeBuilder;
2826
}
2927

3028
private function buildServiceNode(NodeBuilder $serviceNode): void
3129
{
32-
$serviceNode
33-
->scalarNode('dao_namespace')->defaultValue('App\\Daos')->end()
34-
->scalarNode('bean_namespace')->defaultValue('App\\Beans')->end()
35-
->scalarNode('connection')->defaultValue('doctrine.dbal.default_connection')->end()
36-
->arrayNode('naming')
37-
->addDefaultsIfNotSet()
38-
->children()
39-
->scalarNode('bean_prefix')->defaultValue('')->end()
40-
->scalarNode('bean_suffix')->defaultValue('')->end()
41-
->scalarNode('base_bean_prefix')->defaultValue('Abstract')->end()
42-
->scalarNode('base_bean_suffix')->defaultValue('')->end()
43-
->scalarNode('dao_prefix')->defaultValue('')->end()
44-
->scalarNode('dao_suffix')->defaultValue('Dao')->end()
45-
->scalarNode('base_dao_prefix')->defaultValue('Abstract')->end()
46-
->scalarNode('base_dao_suffix')->defaultValue('Dao')->end()
47-
->arrayNode('exceptions')
48-
->prototype('scalar')->end()
49-
->end()
50-
->end()
51-
->end();
30+
$serviceNode->scalarNode('dao_namespace')->defaultValue('App\\Daos');
31+
$serviceNode->scalarNode('bean_namespace')->defaultValue('App\\Beans');
32+
$serviceNode->scalarNode('connection')->defaultValue('doctrine.dbal.default_connection');
33+
34+
$namingNode = $serviceNode->arrayNode('naming')->addDefaultsIfNotSet()->children();
35+
$namingNode->scalarNode('bean_prefix')->defaultValue('');
36+
$namingNode->scalarNode('bean_suffix')->defaultValue('');
37+
$namingNode->scalarNode('base_bean_prefix')->defaultValue('Abstract');
38+
$namingNode->scalarNode('base_bean_suffix')->defaultValue('');
39+
$namingNode->scalarNode('dao_prefix')->defaultValue('');
40+
$namingNode->scalarNode('dao_suffix')->defaultValue('Dao');
41+
$namingNode->scalarNode('base_dao_prefix')->defaultValue('Abstract');
42+
$namingNode->scalarNode('base_dao_suffix')->defaultValue('Dao');
43+
$namingNode->arrayNode('exceptions')->prototype('scalar');
5244
}
5345
}

DependencyInjection/TdbmExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;
55

66

7-
use BrainDiminished\SchemaVersionControl\SchemaVersionControlService;
87
use Doctrine\Common\Cache\FilesystemCache;
98
use Doctrine\Common\Cache\VoidCache;
109
use Doctrine\DBAL\Connection;
@@ -23,6 +22,7 @@
2322
use TheCodingMachine\TDBM\Configuration as TDBMConfiguration;
2423
use TheCodingMachine\TDBM\ConfigurationInterface;
2524
use TheCodingMachine\TDBM\Schema\LockFileSchemaManager;
25+
use TheCodingMachine\TDBM\SchemaVersionControl\SchemaVersionControlService;
2626
use TheCodingMachine\TDBM\TDBMService;
2727
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
2828
use TheCodingMachine\TDBM\Utils\CodeGeneratorListenerInterface;
@@ -255,7 +255,7 @@ private function getAnnotationParserDefinition(): Definition
255255
private function getSchemaManagerDefinition(string $connectionServiceId): Definition
256256
{
257257
$schemaManager = $this->nD(AbstractSchemaManager::class);
258-
$schemaManager->setFactory([new Reference($connectionServiceId), 'getSchemaManager']);
258+
$schemaManager->setFactory([new Reference($connectionServiceId), 'createSchemaManager']);
259259

260260
return $schemaManager;
261261
}

Tests/FunctionalTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Config\Definition\Processor;
99
use Symfony\Bundle\FrameworkBundle\Console\Application;
1010
use Symfony\Component\Console\Tester\ApplicationTester;
11+
use Symfony\Component\HttpKernel\KernelInterface;
1112
use TheCodingMachine\FluidSchema\TdbmFluidSchema;
1213
use TheCodingMachine\TDBM\Bundle\DependencyInjection\Configuration;
1314
use TheCodingMachine\TDBM\Bundle\Tests\Fixtures\PublicService;
@@ -39,7 +40,7 @@ class FunctionalTest extends KernelTestCase
3940

4041
private static $multiDb = false;
4142

42-
protected static function createKernel(array $options = [])
43+
protected static function createKernel(array $options = []): KernelInterface
4344
{
4445
return new TdbmTestingKernel(self::$multiDb);
4546
}
@@ -93,23 +94,22 @@ public function testExceptionsConfiguration(): void
9394
public function testEndToEnd(): void
9495
{
9596
self::$multiDb = true;
96-
self::bootKernel();
97-
$container = self::$container;
97+
$container = self::bootKernel()->getContainer(); // Cannot use self::getContainer() here, as it tries to retrieve test.service_container.
9898

9999
/**
100100
* @var Connection $connectionRoot
101101
*/
102102
$connectionRoot = $container->get('doctrine.dbal.root_connection');
103103

104-
$connectionRoot->getSchemaManager()->dropAndCreateDatabase('test_tdbmbundle');
105-
$connectionRoot->getSchemaManager()->dropAndCreateDatabase('test_tdbmbundle2');
104+
$connectionRoot->createSchemaManager()->dropAndCreateDatabase('test_tdbmbundle');
105+
$connectionRoot->createSchemaManager()->dropAndCreateDatabase('test_tdbmbundle2');
106106

107107
/**
108108
* @var Connection $connection1
109109
*/
110110
$connection1 = $container->get('doctrine.dbal.default_connection');
111111

112-
$fromSchema1 = $connection1->getSchemaManager()->createSchema();
112+
$fromSchema1 = $connection1->createSchemaManager()->createSchema();
113113
$toSchema1 = clone $fromSchema1;
114114

115115
$db = new TdbmFluidSchema($toSchema1, new \TheCodingMachine\FluidSchema\DefaultNamingStrategy($connection1->getDatabasePlatform()));
@@ -131,7 +131,7 @@ public function testEndToEnd(): void
131131
*/
132132
$connection2 = $container->get('doctrine.dbal.other_connection');
133133

134-
$fromSchema2 = $connection2->getSchemaManager()->createSchema();
134+
$fromSchema2 = $connection2->createSchemaManager()->createSchema();
135135
$toSchema2 = clone $fromSchema2;
136136

137137
$db = new TdbmFluidSchema($toSchema2, new \TheCodingMachine\FluidSchema\DefaultNamingStrategy($connection2->getDatabasePlatform()));
@@ -167,8 +167,7 @@ public function testEndToEnd(): void
167167
public function testEndToEnd2(): void
168168
{
169169
self::$multiDb = true;
170-
self::bootKernel();
171-
$container = self::$container;
170+
$container = self::bootKernel()->getContainer(); // Cannot use self::getContainer() here, as it tries to retrieve test.service_container.
172171

173172
// PublicService is a dirty trick to access CountryDao and PersonDao that are private services.
174173
$publicService = $container->get(PublicService::class);

Tests/TdbmTestingKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Symfony\Component\Config\Loader\LoaderInterface;
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;
1111
use Symfony\Component\HttpKernel\Kernel;
12-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1312
use TheCodingMachine\TDBM\Bundle\TdbmBundle;
13+
1414
use function spl_object_hash;
1515

1616
class TdbmTestingKernel extends Kernel
@@ -29,7 +29,7 @@ public function __construct(bool $multiDb = false)
2929
$this->multiDb = $multiDb;
3030
}
3131

32-
public function registerBundles()
32+
public function registerBundles(): iterable
3333
{
3434
return [
3535
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
@@ -107,7 +107,7 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
107107
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
108108
}
109109

110-
public function getCacheDir()
110+
public function getCacheDir(): string
111111
{
112112
return __DIR__.'/../cache/'.($this->multiDb?"multidb":"singledb").spl_object_hash($this);
113113
}

Utils/StubSchemaManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
namespace TheCodingMachine\TDBM\Bundle\Utils;
44

5+
use Doctrine\DBAL\Platforms\AbstractPlatform;
56
use Doctrine\DBAL\Schema\AbstractSchemaManager;
67
use Doctrine\DBAL\Schema\Column;
78
use Doctrine\DBAL\Schema\Schema;
89

910
/**
1011
* A stub for schema manager that simply returns the schema we are providing.
12+
*
13+
* @template-covariant T of AbstractPlatform
14+
* @extends AbstractSchemaManager<T>
1115
*/
1216
class StubSchemaManager extends AbstractSchemaManager
1317
{

composer.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@
2121
}
2222
],
2323
"require" : {
24-
"php": "^7.4 || ^8.0",
25-
"thecodingmachine/tdbm": "~5.3.0",
26-
"doctrine/doctrine-bundle": "^2",
24+
"php": "^8.0",
25+
"thecodingmachine/tdbm": "~6.0.0",
26+
"doctrine/doctrine-bundle": "^2.2.2",
2727
"doctrine/orm": "^2",
28-
"symfony/http-kernel": "^4.1.9 || ^5"
28+
"symfony/http-kernel": "^5.0 || ^6.0"
2929
},
3030
"require-dev": {
31-
"roave/security-advisories": "dev-master",
32-
"symfony/security-bundle": "^4.1.9 || ^5",
33-
"symfony/yaml": "^4.1.9 || ^5",
31+
"roave/security-advisories": "dev-latest",
32+
"symfony/security-bundle": "^5 || ^6",
33+
"symfony/yaml": "^5 || ^6",
3434
"phpunit/phpunit": "^9.5",
35-
"phpstan/phpstan": "^1.2",
36-
"thecodingmachine/tdbm-fluid-schema-builder": "^1.0.0",
37-
"symfony/framework-bundle": "^5.2"
35+
"phpstan/phpstan": "^2.0",
36+
"thecodingmachine/tdbm-fluid-schema-builder": "^1.0 || ^2.0",
37+
"symfony/framework-bundle": "^5.1 || ^6"
3838
},
3939
"scripts": {
40-
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Utils/ -c phpstan.neon --level=8 --no-progress"
40+
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Utils/ --level=8 --no-progress"
4141
},
4242
"autoload" : {
4343
"psr-4" : {
@@ -51,9 +51,7 @@
5151
},
5252
"extra": {
5353
"branch-alias": {
54-
"dev-master": "5.3.x-dev"
54+
"dev-master": "6.0.x-dev"
5555
}
56-
},
57-
"minimum-stability": "dev",
58-
"prefer-stable": true
56+
}
5957
}

phpstan.neon

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)