diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5d9e959..33c19d4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -24,10 +24,10 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.4 coverage: none extensions: filter - tools: composer-dependency-analyser, composer-normalize, composer-require-checker + tools: composer-dependency-analyser, composer-normalize, composer-require-checker, cs2pr - name: Install Composer Dependencies uses: ramsey/composer-install@v3 @@ -47,20 +47,27 @@ jobs: - name: Run PHP CS Fixer run: vendor/bin/php-cs-fixer check --using-cache=no --config vendor/kununu/code-tools/php-cs-fixer.php src/ tests/ + - name: Run PHP_CodeSniffer + id: php-code-sniffer + run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml --colors src/ tests/ + + - name: Show PHP_CodeSniffer results in PR + if: ${{ always() && steps.php-code-sniffer.outcome == 'failure' }} + run: cs2pr ./phpcs-report.xml + - name: Run Rector run: vendor/bin/rector process --ansi --dry-run --config rector-ci.php src/ tests/ - name: Run PHPStan run: vendor/bin/phpstan analyse --ansi - build: + tests: needs: checks - name: PHPUnit + name: Tests runs-on: ubuntu-latest strategy: matrix: php-version: - - 8.3 - 8.4 mysql-version: - 8.0 @@ -175,8 +182,9 @@ jobs: include-hidden-files: true path: tests/.results/ - sonarcloud: - needs: build + code_analysis: + needs: tests + name: Code Analysis runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -185,7 +193,7 @@ jobs: - uses: actions/download-artifact@v4 with: - name: build-8.3-highest-coverage + name: tests-8.4-highest-coverage path: tests/.results/ - name: Fix Code Coverage Paths diff --git a/composer.json b/composer.json index b7ad44b..a20952e 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,10 @@ } ], "require": { - "php": ">=8.3", + "php": ">=8.4", "ext-filter": "*", - "kununu/collections": "^6.4", - "kununu/data-fixtures": "^14.0", + "kununu/collections": "^7.0", + "kununu/data-fixtures": "^15.0", "symfony/config": "^6.4 || ^7.4", "symfony/dependency-injection": "^6.4 || ^7.4", "symfony/framework-bundle": "^6.4 || ^7.4", @@ -37,7 +37,7 @@ "doctrine/doctrine-migrations-bundle": "^3.7", "doctrine/orm": "^3.6", "elasticsearch/elasticsearch": "^7.10", - "kununu/code-tools": "^3.1", + "kununu/code-tools": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^6.2", "nyholm/psr7": "^1.8", "opensearch-project/opensearch-php": "^2.5", @@ -98,6 +98,7 @@ "phpstan": "phpstan", "rector": "rector process --dry-run --config rector-ci.php src/ tests/", "rector-fix": "rector process --config rector-ci.php src/ tests/", + "sniffer": "phpcs", "test": [ "rm -rf tests/App/var/*", "tests/App/bin/setup_databases.sh test", @@ -118,6 +119,7 @@ "phpstan": "Run PHPStan", "rector": "Run Rector in dry-run mode with CI rules", "rector-fix": "Run Rector in fix mode with CI rules", + "sniffer": "Run PHP_CodeSniffer", "test": "Run all tests", "test-coverage": "Run all tests with coverage report", "unit": "Run all unit tests", diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..049034d --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,24 @@ + + + + + + + + + + src/ + tests/ + + + + + + + + + + + + diff --git a/rector-ci.php b/rector-ci.php index 6e0281e..6033b4b 100644 --- a/rector-ci.php +++ b/rector-ci.php @@ -7,7 +7,7 @@ use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector; return RectorConfig::configure() - ->withPhpSets(php83: true) + ->withPhpSets(php84: true) ->withAttributesSets(symfony: true, phpunit: true) ->withComposerBased(phpunit: true, symfony: true) ->withRules([ diff --git a/src/Command/CopyConnectionSchemaCommand.php b/src/Command/CopyConnectionSchemaCommand.php index 3dae735..ae762e3 100644 --- a/src/Command/CopyConnectionSchemaCommand.php +++ b/src/Command/CopyConnectionSchemaCommand.php @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::INVALID; } - $confirmation = (new SymfonyStyle($input, $output)) + $confirmation = new SymfonyStyle($input, $output) ->confirm( sprintf('WARNING! Connection named "%s" schema and data will be PURGED. Do you want to continue?', $to), !$input->isInteractive() diff --git a/src/Command/LoadFixturesCommand.php b/src/Command/LoadFixturesCommand.php index c5f686c..46e3997 100644 --- a/src/Command/LoadFixturesCommand.php +++ b/src/Command/LoadFixturesCommand.php @@ -43,7 +43,7 @@ final protected function execute(InputInterface $input, OutputInterface $output) $fixtureType = static::getFixtureType(); if (!($append = (bool) filter_var($input->getOption(self::OPTION_APPEND), FILTER_VALIDATE_BOOLEAN)) - && !(new SymfonyStyle($input, $output))->confirm( + && !new SymfonyStyle($input, $output)->confirm( sprintf( 'Careful, Fixture type "%s" named "%s" will be purged. Do you want to continue?', $fixtureType, diff --git a/src/DependencyInjection/Compiler/CachePoolCompilerPass.php b/src/DependencyInjection/Compiler/CachePoolCompilerPass.php index 717d8ab..f58847d 100644 --- a/src/DependencyInjection/Compiler/CachePoolCompilerPass.php +++ b/src/DependencyInjection/Compiler/CachePoolCompilerPass.php @@ -27,7 +27,9 @@ public function process(ContainerBuilder $container): void return; } - foreach ($this->getOrchestratorsIds($container, $container->findTaggedServiceIds(self::CACHE_POOL_TAG)) as $id) { + foreach ( + $this->getOrchestratorsIds($container, $container->findTaggedServiceIds(self::CACHE_POOL_TAG)) as $id + ) { $this->buildContainerDefinitions($container, $id); } } diff --git a/src/DependencyInjection/Compiler/HttpClientCompilerPass.php b/src/DependencyInjection/Compiler/HttpClientCompilerPass.php index d181686..034e31d 100644 --- a/src/DependencyInjection/Compiler/HttpClientCompilerPass.php +++ b/src/DependencyInjection/Compiler/HttpClientCompilerPass.php @@ -60,7 +60,11 @@ private function buildOrchestrator(ContainerBuilder $container, string $id): voi ), ], // Executor Definition for HttpClient with provided id - executorDefinitionBuilder: static fn(ContainerBuilder $container, string $baseId, string $purgerId): array => [ + executorDefinitionBuilder: static fn( + ContainerBuilder $container, + string $baseId, + string $purgerId, + ): array => [ sprintf('%s.%s.executor', self::SERVICE_PREFIX, $baseId), new Definition( HttpClientExecutor::class, diff --git a/src/DependencyInjection/KununuTestingExtension.php b/src/DependencyInjection/KununuTestingExtension.php index 5d5d36d..d7b1a55 100755 --- a/src/DependencyInjection/KununuTestingExtension.php +++ b/src/DependencyInjection/KununuTestingExtension.php @@ -3,6 +3,7 @@ namespace Kununu\TestingBundle\DependencyInjection; +use Exception; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -28,10 +29,11 @@ final class KununuTestingExtension extends Extension implements ExtensionConfigu private array $config = []; + /** @throws Exception */ public function load(array $configs, ContainerBuilder $container): void { $this->config = $this->processConfiguration(new Configuration(), $configs); - (new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')))->load('services.yaml'); + new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'))->load('services.yaml'); foreach (self::CONNECTIONS as $section) { if (!empty($this->config[$section])) { diff --git a/tests/App/Fixtures/Connection/ConnectionFixture1.php b/tests/App/Fixtures/Connection/ConnectionFixture1.php index bd2bfc7..7567508 100644 --- a/tests/App/Fixtures/Connection/ConnectionFixture1.php +++ b/tests/App/Fixtures/Connection/ConnectionFixture1.php @@ -14,8 +14,16 @@ final class ConnectionFixture1 implements ConnectionFixtureInterface, Initializa public function load(Connection $connection): void { - $connection->executeStatement('INSERT INTO `table_1` (`name`, `description`) VALUES (\'name\', \'description\');'); - $connection->executeStatement('INSERT INTO `table_2` (`name`, `description`) VALUES (\'name\', \'description\');'); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_1` (`name`, `description`) VALUES ('name', 'description'); +SQL + ); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_2` (`name`, `description`) VALUES ('name', 'description'); +SQL + ); } public function initializeFixture(mixed ...$args): void diff --git a/tests/App/Fixtures/Connection/ConnectionFixture2.php b/tests/App/Fixtures/Connection/ConnectionFixture2.php index d2bf226..52534d5 100644 --- a/tests/App/Fixtures/Connection/ConnectionFixture2.php +++ b/tests/App/Fixtures/Connection/ConnectionFixture2.php @@ -10,7 +10,15 @@ { public function load(Connection $connection): void { - $connection->executeStatement('INSERT INTO `table_1` (`name`, `description`) VALUES (\'name\', \'description\');'); - $connection->executeStatement('INSERT INTO `table_2` (`name`, `description`) VALUES (\'name\', \'description\');'); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_1` (`name`, `description`) VALUES ('name', 'description'); +SQL + ); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_2` (`name`, `description`) VALUES ('name', 'description'); +SQL + ); } } diff --git a/tests/App/Fixtures/Connection/ConnectionFixture3.php b/tests/App/Fixtures/Connection/ConnectionFixture3.php index 65ca8c0..ec31c88 100644 --- a/tests/App/Fixtures/Connection/ConnectionFixture3.php +++ b/tests/App/Fixtures/Connection/ConnectionFixture3.php @@ -10,7 +10,15 @@ { public function load(Connection $connection): void { - $connection->executeStatement('INSERT INTO `table_1` (`name`, `description`) VALUES (\'name3\', \'description3\');'); - $connection->executeStatement('INSERT INTO `table_2` (`name`, `description`) VALUES (\'name3\', \'description3\');'); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_1` (`name`, `description`) VALUES ('name3', 'description3'); +SQL + ); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_2` (`name`, `description`) VALUES ('name3', 'description3'); +SQL + ); } } diff --git a/tests/App/Fixtures/Connection/ConnectionFixture4.php b/tests/App/Fixtures/Connection/ConnectionFixture4.php index bdd14f5..a6ad7c2 100644 --- a/tests/App/Fixtures/Connection/ConnectionFixture4.php +++ b/tests/App/Fixtures/Connection/ConnectionFixture4.php @@ -10,7 +10,15 @@ { public function load(Connection $connection): void { - $connection->executeStatement('INSERT INTO `table_1` (`name`, `description`) VALUES (\'name4\', \'description4\');'); - $connection->executeStatement('INSERT INTO `table_2` (`name`, `description`) VALUES (\'name4\', \'description4\');'); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_1` (`name`, `description`) VALUES ('name4', 'description4'); +SQL + ); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_2` (`name`, `description`) VALUES ('name4', 'description4'); +SQL + ); } } diff --git a/tests/App/Fixtures/Connection/ConnectionFixture5.php b/tests/App/Fixtures/Connection/ConnectionFixture5.php index 8a0ed1f..73a2d47 100644 --- a/tests/App/Fixtures/Connection/ConnectionFixture5.php +++ b/tests/App/Fixtures/Connection/ConnectionFixture5.php @@ -10,6 +10,10 @@ { public function load(Connection $connection): void { - $connection->executeStatement('INSERT INTO `table_3` (`name`, `description`) VALUES (\'my_name\', \'description5\');'); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_3` (`name`, `description`) VALUES ('my_name', 'description5'); +SQL + ); } } diff --git a/tests/App/Fixtures/Connection/ConnectionFixture6.php b/tests/App/Fixtures/Connection/ConnectionFixture6.php index 5ce95f7..5c9604c 100644 --- a/tests/App/Fixtures/Connection/ConnectionFixture6.php +++ b/tests/App/Fixtures/Connection/ConnectionFixture6.php @@ -10,6 +10,10 @@ { public function load(Connection $connection): void { - $connection->executeStatement('INSERT INTO `table_3` (`name`, `description`) VALUES (\'my_name\', \'description6\');'); + $connection->executeStatement( + <<<'SQL' +INSERT INTO `table_3` (`name`, `description`) VALUES ('my_name', 'description6'); +SQL + ); } } diff --git a/tests/App/Fixtures/DynamoDb/DynamoDbFixture1.php b/tests/App/Fixtures/DynamoDb/DynamoDbFixture1.php index 0d75d21..a4b51ef 100644 --- a/tests/App/Fixtures/DynamoDb/DynamoDbFixture1.php +++ b/tests/App/Fixtures/DynamoDb/DynamoDbFixture1.php @@ -26,7 +26,8 @@ protected function configure(): void ]), ]; - $this->setTableName('my_table') + $this + ->setTableName('my_table') ->addRecords($records); } } diff --git a/tests/App/Fixtures/DynamoDb/DynamoDbFixture2.php b/tests/App/Fixtures/DynamoDb/DynamoDbFixture2.php index 15de974..3400e28 100644 --- a/tests/App/Fixtures/DynamoDb/DynamoDbFixture2.php +++ b/tests/App/Fixtures/DynamoDb/DynamoDbFixture2.php @@ -16,7 +16,8 @@ protected function configure(): void Value::stringValue('attr_2', 'Other test 4'), ]); - $this->setTableName('other_table') + $this + ->setTableName('other_table') ->addRecord($record); } } diff --git a/tests/App/config/bootstrap.php b/tests/App/config/bootstrap.php index 63cffc0..e0a7264 100644 --- a/tests/App/config/bootstrap.php +++ b/tests/App/config/bootstrap.php @@ -6,4 +6,5 @@ $_SERVER += $_ENV; $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; $_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; -$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = + (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/tests/Unit/KununuTestingBundleTest.php b/tests/Unit/KununuTestingBundleTest.php index 7f26250..936b59a 100644 --- a/tests/Unit/KununuTestingBundleTest.php +++ b/tests/Unit/KununuTestingBundleTest.php @@ -34,7 +34,7 @@ static function($subject) use ($container, &$executedCompilerPasses): MockObject } ); - (new KununuTestingBundle())->build($container); + new KununuTestingBundle()->build($container); self::assertEquals( [ diff --git a/tests/Unit/Service/OrchestratorTest.php b/tests/Unit/Service/OrchestratorTest.php index e19b819..173f1c3 100644 --- a/tests/Unit/Service/OrchestratorTest.php +++ b/tests/Unit/Service/OrchestratorTest.php @@ -69,6 +69,6 @@ private function getNamedFixtureMock(string $name): MockObject&FixtureInterface private function generateMockClassName(string $prefix): string { - return sprintf('%s%s', $prefix, md5((new DateTime())->format('Y-m-d H:i:s.uP'))); + return sprintf('%s%s', $prefix, md5(new DateTime()->format('Y-m-d H:i:s.uP'))); } } diff --git a/tests/Unit/Service/SchemaCopy/Factory/AdapterFactoryTest.php b/tests/Unit/Service/SchemaCopy/Factory/AdapterFactoryTest.php index f6abbc5..5c0ba17 100644 --- a/tests/Unit/Service/SchemaCopy/Factory/AdapterFactoryTest.php +++ b/tests/Unit/Service/SchemaCopy/Factory/AdapterFactoryTest.php @@ -26,7 +26,7 @@ public function testCreateAdapter(string $platformClass, ?string $expectedType): $this->expectException(UnsupportedDatabasePlatformException::class); } - $adapter = (new AdapterFactory())->createAdapter($connection); + $adapter = new AdapterFactory()->createAdapter($connection); if (null !== $expectedType) { self::assertEquals($expectedType, $adapter->type()); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8dea474..76b7d97 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,4 +11,4 @@ // https://github.com/symfony/symfony/issues/53812#issuecomment-1962740145 set_exception_handler([new ErrorHandler(), 'handleException']); -(new Dotenv())->bootEnv(dirname(__DIR__) . '/tests/App/.env'); +new Dotenv()->bootEnv(dirname(__DIR__) . '/tests/App/.env');