Skip to content

Commit

Permalink
no-issue - Add smock test on command
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMellerin committed Nov 22, 2023
1 parent 3925762 commit f0a5c5f
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 30 deletions.
43 changes: 22 additions & 21 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
services:
# Commands
db_tools.command.anonymization.run:
class: MakinaCorpus\DbToolsBundle\Command\Anonymization\AnonymizeCommand
arguments:
- '@db_tools.anonymization.anonymizator.factory'
- '%doctrine.default_connection%'
tags: ['console.command']
db_tools.command.anonymization.list:
class: MakinaCorpus\DbToolsBundle\Command\AnonymizerListCommand
class: MakinaCorpus\DbToolsBundle\Command\Anonymization\AnonymizerListCommand
arguments:
- '@db_tools.anonymization.anonymizer.registry'
tags: ['console.command']
db_tools.command.anonymization.check:
class: MakinaCorpus\DbToolsBundle\Command\AnonymizationCheckCommand
db_tools.command.clean:
class: MakinaCorpus\DbToolsBundle\Command\Anonymization\CleanCommand
arguments:
- '@db_tools.anonymization.anonymizator.factory'
- '%doctrine.default_connection%'
tags: ['console.command']
db_tools.command.anonymization.run:
class: MakinaCorpus\DbToolsBundle\Command\AnonymizeCommand
db_tools.command.anonymization.check:
class: MakinaCorpus\DbToolsBundle\Command\Anonymization\ConfigCheckCommand
arguments:
- '@db_tools.anonymization.anonymizator.factory'
- '%doctrine.default_connection%'
tags: ['console.command']
db_tools.command.clean:
class: MakinaCorpus\DbToolsBundle\Command\CleanCommand
db_tools.command.backup:
class: MakinaCorpus\DbToolsBundle\Command\BackupCommand
arguments:
- '@db_tools.anonymization.anonymizator.factory'
- '%doctrine.default_connection%'
- '%db_tools.excluded_tables%'
- '@db_tools.backupper.factory.registry'
- '@db_tools.storage'
tags: ['console.command']
db_tools.command.check:
class: MakinaCorpus\DbToolsBundle\Command\CheckCommand
Expand All @@ -29,14 +37,15 @@ services:
- '@db_tools.backupper.factory.registry'
- '@db_tools.restorer.factory.registry'
tags: ['console.command']
db_tools.command.backup:
class: MakinaCorpus\DbToolsBundle\Command\BackupCommand
db_tools.command.gdprify:
class: MakinaCorpus\DbToolsBundle\Command\GdprifyCommand
arguments:
- '%doctrine.default_connection%'
- '%db_tools.excluded_tables%'
- '@db_tools.restorer.factory.registry'
- '@db_tools.backupper.factory.registry'
- '@db_tools.storage'
- '@db_tools.anonymization.anonymizator.factory'
tags: ['console.command']

db_tools.command.restore:
class: MakinaCorpus\DbToolsBundle\Command\RestoreCommand
arguments:
Expand All @@ -50,14 +59,6 @@ services:
- '%doctrine.default_connection%'
- '@db_tools.stats_provider.factory.registry'
tags: ['console.command']
db_tools.command.gdprify:
class: MakinaCorpus\DbToolsBundle\Command\GdprifyCommand
arguments:
- '%doctrine.default_connection%'
- '@db_tools.restorer.factory.registry'
- '@db_tools.backupper.factory.registry'
- '@db_tools.anonymization.anonymizator.factory'
tags: ['console.command']

# Utilities
db_tools.storage:
Expand Down
5 changes: 5 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ do_test() {
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER="root" \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql57:3306/test_db?serverVersion=5.7 \
phpunit vendor/bin/phpunit $@

section_title "Running tests with MySQL 8"
Expand All @@ -64,6 +65,7 @@ do_test() {
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=root \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql80:3306/test_db?serverVersion=8 \
phpunit vendor/bin/phpunit $@

section_title "Running tests with MariaDB 11"
Expand All @@ -76,6 +78,7 @@ do_test() {
-e DBAL_ROOT_PASSWORD="password" \
-e DBAL_ROOT_USER="root" \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mariadb11:3306/test_db?serverVersion=11.1.3-MariaDB \
phpunit vendor/bin/phpunit $@

section_title "Running tests with PostgreSQL 10"
Expand All @@ -88,6 +91,7 @@ do_test() {
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=postgres \
-e DBAL_USER=postgres \
-e DATABASE_URL="postgresql://postgres:password@postgresql10:5432/test_db?serverVersion=10&charset=utf8" \
phpunit vendor/bin/phpunit $@

section_title "Running tests with PostgreSQL 16"
Expand All @@ -100,6 +104,7 @@ do_test() {
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=postgres \
-e DBAL_USER=postgres \
-e DATABASE_URL="postgresql://postgres:password@postgresql16:5432/test_db?serverVersion=16&charset=utf8" \
phpunit vendor/bin/phpunit $@
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
networks:
- db-tools-test
mariadb11:
image: mariadb:11
image: mariadb:11.1.3
restart: 'no'
environment:
MYSQL_DATABASE: test_db
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<env name="DBAL_PORT" value=""/>
<env name="DBAL_USER" value=""/>
<env name="DBAL_PASSWORD" value=""/>
<env name="KERNEL_CLASS" value="MakinaCorpus\DbToolsBundle\Tests\TestKernel"/>
</php>
<testsuites>
<testsuite name="Functional">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Command;
namespace MakinaCorpus\DbToolsBundle\Command\Anonymization;

use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Command;
namespace MakinaCorpus\DbToolsBundle\Command\Anonymization;

use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\AbstractAnonymizer;
use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\AnonymizerRegistry;
use MakinaCorpus\DbToolsBundle\Attribute\AsAnonymizer;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Command;
namespace MakinaCorpus\DbToolsBundle\Command\Anonymization;

use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Command;
namespace MakinaCorpus\DbToolsBundle\Command\Anonymization;

use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory;
use MakinaCorpus\DbToolsBundle\Anonymization\Config\AnonymizerConfig;
Expand All @@ -13,8 +13,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'db-tools:anonymization:check', description: 'Check and dump anonymization configuration.')]
class AnonymizationCheckCommand extends Command
#[AsCommand(name: 'db-tools:anonymization:config-check', description: 'Check and dump anonymization configuration.')]
class ConfigCheckCommand extends Command
{
public function __construct(
private AnonymizatorFactory $anonymizatorFactory,
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/DbToolsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function load(array $configs, ContainerBuilder $container)
if (\is_dir($defaultDirectory)) {
$anonymizerPaths[] = '%kernel.project_dir%/src/Anonymizer';
}
$anonymizerPaths[] = \realpath(\dirname(__DIR__)) . '/Anonymizer';
$anonymizerPaths[] = \realpath(\dirname(__DIR__)) . '/Anonymization/Anonymizer';

$container->setParameter('db_tools.anonymization.anonymizer.paths', $anonymizerPaths);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Functional/Command/Anonymization/AnonymizeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class AnonymizeCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('db-tools:anonymization:run');
$commandTester = new CommandTester($command);
$commandTester->execute(
[
'--force' => true
],
[
'interactive' => false,
'capture_stderr_separately' => true
]
);

$commandTester->assertCommandIsSuccessful();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class AnonymizerListCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('db-tools:anonymization:list');
$commandTester = new CommandTester($command);
$commandTester->execute(
[],
[
'capture_stderr_separately' => true
]
);

$commandTester->assertCommandIsSuccessful();
}
}
32 changes: 32 additions & 0 deletions tests/Functional/Command/Anonymization/CleanCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class CleanCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('db-tools:anonymization:clean');
$commandTester = new CommandTester($command);
$commandTester->execute(
[
'--force' => true
],
[
'interactive' => false,
'capture_stderr_separately' => true
]
);

$commandTester->assertCommandIsSuccessful();
}
}
30 changes: 30 additions & 0 deletions tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class ConfigCheckCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('db-tools:anonymization:config-check');
$commandTester = new CommandTester($command);
$commandTester->execute(
[],
[
'interactive' => false,
'capture_stderr_separately' => true
]
);

$commandTester->assertCommandIsSuccessful();
}
}
24 changes: 24 additions & 0 deletions tests/Functional/Command/BackupCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class BackupCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('db-tools:backup');
$commandTester = new CommandTester($command);
$commandTester->execute([]);

$commandTester->assertCommandIsSuccessful();
}
}
24 changes: 24 additions & 0 deletions tests/Functional/Command/CheckCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class CheckCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('db-tools:check');
$commandTester = new CommandTester($command);
$commandTester->execute([]);

$commandTester->assertCommandIsSuccessful();
}
}
26 changes: 26 additions & 0 deletions tests/Functional/Command/GdprifyCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class GdprifyCommandTest extends KernelTestCase
{
public function testExecute(): void
{
$this->markTestSkipped("Hard to test for know.");

$kernel = self::bootKernel();

Check failure on line 17 in tests/Functional/Command/GdprifyCommandTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.2)

Unreachable statement - code above always terminates.
$application = new Application($kernel);

$command = $application->find('db-tools:gdprify');
$commandTester = new CommandTester($command);
$commandTester->execute([]);

$commandTester->assertCommandIsSuccessful();
}
}
Loading

0 comments on commit f0a5c5f

Please sign in to comment.