Skip to content

⬆️ Symfony 6 support #34

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

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

services:
Expand All @@ -28,7 +27,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -41,14 +40,14 @@ jobs:
tools: "cs2pr"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install dependencies with composer"
run: "composer install --no-interaction --no-progress --no-suggest"
run: "composer install --no-interaction --no-progress"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml"
Expand All @@ -67,7 +66,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

services:
Expand All @@ -81,7 +79,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -93,14 +91,14 @@ jobs:
coverage: "pcov"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress --no-suggest --prefer-lowest"
run: "composer update --no-interaction --no-progress --prefer-lowest"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml"
46 changes: 19 additions & 27 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,43 @@

namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('tdbm');
$rootNode = $treeBuilder->getRootNode();
assert($rootNode instanceof ArrayNodeDefinition);

$rootNodeChildren = $rootNode->children();

$this->buildServiceNode($rootNodeChildren);

$rootNodeServices = $rootNodeChildren->arrayNode('databases')->arrayPrototype()->children();
$this->buildServiceNode($rootNodeServices);
$rootNodeServices->end()->end()->end();

$rootNodeChildren->end();
$rootNodeDatabases = $rootNodeChildren->arrayNode('databases')->arrayPrototype()->children();
$this->buildServiceNode($rootNodeDatabases);

return $treeBuilder;
}

private function buildServiceNode(NodeBuilder $serviceNode): void
{
$serviceNode
->scalarNode('dao_namespace')->defaultValue('App\\Daos')->end()
->scalarNode('bean_namespace')->defaultValue('App\\Beans')->end()
->scalarNode('connection')->defaultValue('doctrine.dbal.default_connection')->end()
->arrayNode('naming')
->addDefaultsIfNotSet()
->children()
->scalarNode('bean_prefix')->defaultValue('')->end()
->scalarNode('bean_suffix')->defaultValue('')->end()
->scalarNode('base_bean_prefix')->defaultValue('Abstract')->end()
->scalarNode('base_bean_suffix')->defaultValue('')->end()
->scalarNode('dao_prefix')->defaultValue('')->end()
->scalarNode('dao_suffix')->defaultValue('Dao')->end()
->scalarNode('base_dao_prefix')->defaultValue('Abstract')->end()
->scalarNode('base_dao_suffix')->defaultValue('Dao')->end()
->arrayNode('exceptions')
->prototype('scalar')->end()
->end()
->end()
->end();
$serviceNode->scalarNode('dao_namespace')->defaultValue('App\\Daos');
$serviceNode->scalarNode('bean_namespace')->defaultValue('App\\Beans');
$serviceNode->scalarNode('connection')->defaultValue('doctrine.dbal.default_connection');

$namingNode = $serviceNode->arrayNode('naming')->addDefaultsIfNotSet()->children();
$namingNode->scalarNode('bean_prefix')->defaultValue('');
$namingNode->scalarNode('bean_suffix')->defaultValue('');
$namingNode->scalarNode('base_bean_prefix')->defaultValue('Abstract');
$namingNode->scalarNode('base_bean_suffix')->defaultValue('');
$namingNode->scalarNode('dao_prefix')->defaultValue('');
$namingNode->scalarNode('dao_suffix')->defaultValue('Dao');
$namingNode->scalarNode('base_dao_prefix')->defaultValue('Abstract');
$namingNode->scalarNode('base_dao_suffix')->defaultValue('Dao');
$namingNode->arrayNode('exceptions')->prototype('scalar');
}
}
4 changes: 2 additions & 2 deletions DependencyInjection/TdbmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;


use BrainDiminished\SchemaVersionControl\SchemaVersionControlService;
use Doctrine\Common\Cache\FilesystemCache;
use Doctrine\Common\Cache\VoidCache;
use Doctrine\DBAL\Connection;
Expand All @@ -23,6 +22,7 @@
use TheCodingMachine\TDBM\Configuration as TDBMConfiguration;
use TheCodingMachine\TDBM\ConfigurationInterface;
use TheCodingMachine\TDBM\Schema\LockFileSchemaManager;
use TheCodingMachine\TDBM\SchemaVersionControl\SchemaVersionControlService;
use TheCodingMachine\TDBM\TDBMService;
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
use TheCodingMachine\TDBM\Utils\CodeGeneratorListenerInterface;
Expand Down Expand Up @@ -255,7 +255,7 @@ private function getAnnotationParserDefinition(): Definition
private function getSchemaManagerDefinition(string $connectionServiceId): Definition
{
$schemaManager = $this->nD(AbstractSchemaManager::class);
$schemaManager->setFactory([new Reference($connectionServiceId), 'getSchemaManager']);
$schemaManager->setFactory([new Reference($connectionServiceId), 'createSchemaManager']);

return $schemaManager;
}
Expand Down
17 changes: 8 additions & 9 deletions Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Config\Definition\Processor;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\HttpKernel\KernelInterface;
use TheCodingMachine\FluidSchema\TdbmFluidSchema;
use TheCodingMachine\TDBM\Bundle\DependencyInjection\Configuration;
use TheCodingMachine\TDBM\Bundle\Tests\Fixtures\PublicService;
Expand Down Expand Up @@ -39,7 +40,7 @@ class FunctionalTest extends KernelTestCase

private static $multiDb = false;

protected static function createKernel(array $options = [])
protected static function createKernel(array $options = []): KernelInterface
{
return new TdbmTestingKernel(self::$multiDb);
}
Expand Down Expand Up @@ -93,23 +94,22 @@ public function testExceptionsConfiguration(): void
public function testEndToEnd(): void
{
self::$multiDb = true;
self::bootKernel();
$container = self::$container;
$container = self::bootKernel()->getContainer(); // Cannot use self::getContainer() here, as it tries to retrieve test.service_container.

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

$connectionRoot->getSchemaManager()->dropAndCreateDatabase('test_tdbmbundle');
$connectionRoot->getSchemaManager()->dropAndCreateDatabase('test_tdbmbundle2');
$connectionRoot->createSchemaManager()->dropAndCreateDatabase('test_tdbmbundle');
$connectionRoot->createSchemaManager()->dropAndCreateDatabase('test_tdbmbundle2');

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

$fromSchema1 = $connection1->getSchemaManager()->createSchema();
$fromSchema1 = $connection1->createSchemaManager()->createSchema();
$toSchema1 = clone $fromSchema1;

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

$fromSchema2 = $connection2->getSchemaManager()->createSchema();
$fromSchema2 = $connection2->createSchemaManager()->createSchema();
$toSchema2 = clone $fromSchema2;

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

// PublicService is a dirty trick to access CountryDao and PersonDao that are private services.
$publicService = $container->get(PublicService::class);
Expand Down
6 changes: 3 additions & 3 deletions Tests/TdbmTestingKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use TheCodingMachine\TDBM\Bundle\TdbmBundle;

use function spl_object_hash;

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

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

public function getCacheDir()
public function getCacheDir(): string
{
return __DIR__.'/../cache/'.($this->multiDb?"multidb":"singledb").spl_object_hash($this);
}
Expand Down
4 changes: 4 additions & 0 deletions Utils/StubSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace TheCodingMachine\TDBM\Bundle\Utils;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Schema;

/**
* A stub for schema manager that simply returns the schema we are providing.
*
* @template-covariant T of AbstractPlatform
* @extends AbstractSchemaManager<T>
*/
class StubSchemaManager extends AbstractSchemaManager
{
Expand Down
28 changes: 13 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
}
],
"require" : {
"php": "^7.4 || ^8.0",
"thecodingmachine/tdbm": "~5.3.0",
"doctrine/doctrine-bundle": "^2",
"php": "^8.0",
"thecodingmachine/tdbm": "~6.0.0",
"doctrine/doctrine-bundle": "^2.2.2",
"doctrine/orm": "^2",
"symfony/http-kernel": "^4.1.9 || ^5"
"symfony/http-kernel": "^5.0 || ^6.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"symfony/security-bundle": "^4.1.9 || ^5",
"symfony/yaml": "^4.1.9 || ^5",
"roave/security-advisories": "dev-latest",
"symfony/security-bundle": "^5 || ^6",
"symfony/yaml": "^5 || ^6",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.2",
"thecodingmachine/tdbm-fluid-schema-builder": "^1.0.0",
"symfony/framework-bundle": "^5.2"
"phpstan/phpstan": "^2.0",
"thecodingmachine/tdbm-fluid-schema-builder": "^1.0 || ^2.0",
"symfony/framework-bundle": "^5.1 || ^6"
},
"scripts": {
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Utils/ -c phpstan.neon --level=8 --no-progress"
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Utils/ --level=8 --no-progress"
},
"autoload" : {
"psr-4" : {
Expand All @@ -51,9 +51,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.3.x-dev"
"dev-master": "6.0.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
6 changes: 0 additions & 6 deletions phpstan.neon

This file was deleted.