Skip to content
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
24 changes: 16 additions & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="code-tools"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/refs/heads/master/phpcs.xsd">
<config name="installed_paths" value="vendor/kununu/code-tools"/>

<arg name="colors"/>
<arg name="parallel" value="75"/>
<arg value="p"/>
<arg value="n"/>

<file>src/</file>
<file>tests/</file>

<!-- Include all Kununu rules -->
<rule ref="Kununu"/>

<!-- Customize Rules according to project needs -->
<rule ref="Kununu.Files.LineLength">
<properties>
<property name="ignoreComments" value="true"/>
<property name="ignoreUseStatements" value="true"/>
</properties>
</rule>
</ruleset>
2 changes: 1 addition & 1 deletion rector-ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CopyConnectionSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Command/LoadFixturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/DependencyInjection/KununuTestingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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])) {
Expand Down
12 changes: 10 additions & 2 deletions tests/App/Fixtures/Connection/ConnectionFixture1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions tests/App/Fixtures/Connection/ConnectionFixture2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
12 changes: 10 additions & 2 deletions tests/App/Fixtures/Connection/ConnectionFixture3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
12 changes: 10 additions & 2 deletions tests/App/Fixtures/Connection/ConnectionFixture4.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
6 changes: 5 additions & 1 deletion tests/App/Fixtures/Connection/ConnectionFixture5.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
6 changes: 5 additions & 1 deletion tests/App/Fixtures/Connection/ConnectionFixture6.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
3 changes: 2 additions & 1 deletion tests/App/Fixtures/DynamoDb/DynamoDbFixture1.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected function configure(): void
]),
];

$this->setTableName('my_table')
$this
->setTableName('my_table')
->addRecords($records);
}
}
3 changes: 2 additions & 1 deletion tests/App/Fixtures/DynamoDb/DynamoDbFixture2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion tests/App/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion tests/Unit/KununuTestingBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static function($subject) use ($container, &$executedCompilerPasses): MockObject
}
);

(new KununuTestingBundle())->build($container);
new KununuTestingBundle()->build($container);

self::assertEquals(
[
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/OrchestratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');