diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1eaa9be..82ef0ba 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.0" services: @@ -28,7 +27,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" with: fetch-depth: 2 @@ -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" @@ -67,7 +66,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.0" services: @@ -81,7 +79,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" with: fetch-depth: 2 @@ -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" diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ceb16f9..a26ba3d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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'); } } diff --git a/DependencyInjection/TdbmExtension.php b/DependencyInjection/TdbmExtension.php index 5558b13..38038f7 100644 --- a/DependencyInjection/TdbmExtension.php +++ b/DependencyInjection/TdbmExtension.php @@ -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; @@ -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; @@ -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; } diff --git a/Tests/FunctionalTest.php b/Tests/FunctionalTest.php index 72f1a48..df96577 100644 --- a/Tests/FunctionalTest.php +++ b/Tests/FunctionalTest.php @@ -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; @@ -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); } @@ -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())); @@ -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())); @@ -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); diff --git a/Tests/TdbmTestingKernel.php b/Tests/TdbmTestingKernel.php index 309efbe..84826c4 100644 --- a/Tests/TdbmTestingKernel.php +++ b/Tests/TdbmTestingKernel.php @@ -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 @@ -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(), @@ -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); } diff --git a/Utils/StubSchemaManager.php b/Utils/StubSchemaManager.php index 2232437..c8572a6 100644 --- a/Utils/StubSchemaManager.php +++ b/Utils/StubSchemaManager.php @@ -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 */ class StubSchemaManager extends AbstractSchemaManager { diff --git a/composer.json b/composer.json index f23e406..57a6579 100644 --- a/composer.json +++ b/composer.json @@ -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" : { @@ -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 + } } diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 63e8fb3..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,6 +0,0 @@ -parameters: - ignoreErrors: - - "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition::children\\(\\)#" - - '#Cannot call method scalarNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#' -#includes: -# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon