From aa0f671cfc896b8242b089d112c5500b44785e18 Mon Sep 17 00:00:00 2001
From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com>
Date: Tue, 29 Aug 2023 19:53:46 -0400
Subject: [PATCH] Raise Mutation Test 100%. (#195)
---
.github/workflows/build.yml | 1 +
.github/workflows/composer-require-checker.yml | 1 +
.github/workflows/mariadb.yml | 1 +
.github/workflows/mssql.yml | 1 +
.github/workflows/mutation.yml | 4 ++--
.github/workflows/mysql.yml | 1 +
.github/workflows/oracle.yml | 1 +
.github/workflows/pgsql.yml | 1 +
.github/workflows/sqlite.yml | 1 +
.github/workflows/static.yml | 1 +
src/Command/CreateCommand.php | 2 +-
src/Command/DownCommand.php | 2 +-
src/Command/HistoryCommand.php | 2 +-
src/Command/NewCommand.php | 13 +++++--------
src/Command/RedoCommand.php | 2 +-
src/Command/UpdateCommand.php | 6 ++----
tests/Common/Command/AbstractCreateCommandTest.php | 5 +++++
tests/Common/Command/AbstractNewCommandTest.php | 4 ++++
tests/Common/Command/AbstractUpdateCommandTest.php | 10 +++++++++-
tests/Driver/Mssql/CreateCommandTest.php | 1 +
tests/Driver/Mssql/NewCommandTest.php | 1 +
tests/Driver/Mysql/CreateCommandTest.php | 1 +
tests/Driver/Mysql/NewCommandTest.php | 1 +
tests/Driver/Oracle/CreateCommandTest.php | 1 +
tests/Driver/Oracle/NewCommandTest.php | 1 +
tests/Driver/Pgsql/CreateCommandTest.php | 1 +
tests/Driver/Pgsql/NewCommandTest.php | 1 +
tests/Driver/Sqlite/CreateCommandTest.php | 1 +
tests/Driver/Sqlite/NewCommandTest.php | 1 +
29 files changed, 50 insertions(+), 19 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 9716fd67..c51db46c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml
index 6cf3cefa..c166d270 100644
--- a/.github/workflows/composer-require-checker.yml
+++ b/.github/workflows/composer-require-checker.yml
@@ -11,6 +11,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/mariadb.yml b/.github/workflows/mariadb.yml
index add4b7e1..07d1c035 100644
--- a/.github/workflows/mariadb.yml
+++ b/.github/workflows/mariadb.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/mssql.yml b/.github/workflows/mssql.yml
index 5344ea8a..e3a9eb5d 100644
--- a/.github/workflows/mssql.yml
+++ b/.github/workflows/mssql.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml
index 1cd5da80..78cbc9b3 100644
--- a/.github/workflows/mutation.yml
+++ b/.github/workflows/mutation.yml
@@ -38,7 +38,7 @@ jobs:
- ubuntu-latest
php:
- - 8.1
+ - 8.0
services:
postgres:
@@ -72,6 +72,6 @@ jobs:
- name: Run infection.
run: |
- vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered --test-framework-options="--testsuite=Pgsql,Sqlite"
+ vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered --test-framework-options="--testsuite=Pgsql"
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml
index d6451830..79d50e0e 100644
--- a/.github/workflows/mysql.yml
+++ b/.github/workflows/mysql.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/oracle.yml b/.github/workflows/oracle.yml
index 99beee46..b7f9f628 100644
--- a/.github/workflows/oracle.yml
+++ b/.github/workflows/oracle.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/pgsql.yml b/.github/workflows/pgsql.yml
index 3fa6313d..1ff887a8 100644
--- a/.github/workflows/pgsql.yml
+++ b/.github/workflows/pgsql.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml
index 04e059d8..9a8841d6 100644
--- a/.github/workflows/sqlite.yml
+++ b/.github/workflows/sqlite.yml
@@ -10,6 +10,7 @@ on:
- 'psalm.xml'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml
index 19700cf4..b26dcee7 100644
--- a/.github/workflows/static.yml
+++ b/.github/workflows/static.yml
@@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'
push:
+ branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
diff --git a/src/Command/CreateCommand.php b/src/Command/CreateCommand.php
index ec69f0a7..948d3aac 100644
--- a/src/Command/CreateCommand.php
+++ b/src/Command/CreateCommand.php
@@ -72,7 +72,7 @@ public function __construct(
parent::__construct();
}
- public function configure(): void
+ protected function configure(): void
{
$this
->addArgument('name', InputArgument::REQUIRED, 'Table name to generate migration for.')
diff --git a/src/Command/DownCommand.php b/src/Command/DownCommand.php
index daf6848e..f49d8895 100644
--- a/src/Command/DownCommand.php
+++ b/src/Command/DownCommand.php
@@ -45,7 +45,7 @@ public function __construct(
parent::__construct();
}
- public function configure(): void
+ protected function configure(): void
{
$this
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'Number of migrations to revert.', 1)
diff --git a/src/Command/HistoryCommand.php b/src/Command/HistoryCommand.php
index a8d79399..d9d19dda 100644
--- a/src/Command/HistoryCommand.php
+++ b/src/Command/HistoryCommand.php
@@ -38,7 +38,7 @@ public function __construct(
parent::__construct();
}
- public function configure(): void
+ protected function configure(): void
{
$this->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'Maximum number of migrations to display.', null);
}
diff --git a/src/Command/NewCommand.php b/src/Command/NewCommand.php
index 8230f555..baa4a979 100644
--- a/src/Command/NewCommand.php
+++ b/src/Command/NewCommand.php
@@ -12,7 +12,6 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Yiisoft\Yii\Db\Migration\Service\MigrationService;
-use function array_slice;
use function count;
/**
@@ -35,7 +34,7 @@ public function __construct(private MigrationService $migrationService)
parent::__construct();
}
- public function configure(): void
+ protected function configure(): void
{
$this
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'Number of migrations to history.', '10');
@@ -68,18 +67,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$n = count($migrations);
+ $migrationWord = $n === 1 ? 'migration' : 'migrations';
if ($limit && $n > $limit) {
- $migrations = array_slice($migrations, 0, $limit);
- $io->warning(
- "Showing $limit out of $n new " . ($n === 1 ? 'migration' : 'migrations') . ":\n"
- );
+ $io->warning("Showing $limit out of $n new $migrationWord:\n");
} else {
- $io->section("Found $n new " . ($n === 1 ? 'migration' : 'migrations') . ':');
+ $io->section("Found $n new $migrationWord:");
}
foreach ($migrations as $migration) {
- $output->writeln("\t" . $migration . '');
+ $output->writeln("\t{$migration}");
}
$this->migrationService->databaseConnection();
diff --git a/src/Command/RedoCommand.php b/src/Command/RedoCommand.php
index fcf9132d..6f01ae76 100644
--- a/src/Command/RedoCommand.php
+++ b/src/Command/RedoCommand.php
@@ -49,7 +49,7 @@ public function __construct(
parent::__construct();
}
- public function configure(): void
+ protected function configure(): void
{
$this
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'Number of migrations to redo.', null);
diff --git a/src/Command/UpdateCommand.php b/src/Command/UpdateCommand.php
index 734467b3..8de3d1fb 100644
--- a/src/Command/UpdateCommand.php
+++ b/src/Command/UpdateCommand.php
@@ -40,12 +40,10 @@ public function __construct(
private Migrator $migrator,
ConsoleMigrationInformer $informer
) {
- $this->migrator->setInformer($informer);
-
parent::__construct();
}
- public function configure(): void
+ protected function configure(): void
{
$this->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'Number of migrations to apply.', '0');
}
@@ -53,7 +51,7 @@ public function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
- $this->migrator->setIO($io);
+
$this->migrationService->setIO($io);
$this->updateRunner->setIO($io);
diff --git a/tests/Common/Command/AbstractCreateCommandTest.php b/tests/Common/Command/AbstractCreateCommandTest.php
index 70dd6143..1674fecb 100644
--- a/tests/Common/Command/AbstractCreateCommandTest.php
+++ b/tests/Common/Command/AbstractCreateCommandTest.php
@@ -21,6 +21,7 @@ abstract class AbstractCreateCommandTest extends TestCase
use AssertTrait;
protected ContainerInterface $container;
+ protected string $driverName = '';
public function testCreateTableWithPath(): void
{
@@ -64,8 +65,12 @@ public function down(MigrationBuilder \$b): void
$generatedMigrationCode = file_get_contents($migrationsPath . '/' . $className . '.php');
$this->assertSame(Command::SUCCESS, $exitCode);
+ $this->assertStringContainsString($className, $output);
+ $this->assertStringContainsString('CreatePostTable', $output);
$this->assertStringContainsString('Create new migration y/n:', $output);
$this->assertEqualsWithoutLE($expectedMigrationCode, $generatedMigrationCode);
+ $this->assertStringContainsString('[OK] New migration created successfully.', $output);
+ $this->assertStringContainsString('Database connection: ' . $this->driverName, $output);
}
public function testCreateTableWithNamespace(): void
diff --git a/tests/Common/Command/AbstractNewCommandTest.php b/tests/Common/Command/AbstractNewCommandTest.php
index f0a3135a..f0b76659 100644
--- a/tests/Common/Command/AbstractNewCommandTest.php
+++ b/tests/Common/Command/AbstractNewCommandTest.php
@@ -15,6 +15,7 @@
abstract class AbstractNewCommandTest extends TestCase
{
protected ContainerInterface $container;
+ protected string $driverName = '';
public function testExecuteWithNamespace(): void
{
@@ -53,6 +54,7 @@ public function testExecuteWithNamespace(): void
$this->assertStringContainsString($classCreateUser, $output);
$this->assertStringContainsString($classCreateTag, $output);
$this->assertSame(2, substr_count($output, MigrationHelper::NAMESPACE));
+ $this->assertStringContainsString('Database connection: ' . $this->driverName, $output);
}
public function testExecuteWithPath(): void
@@ -102,6 +104,7 @@ public function testIncorrectLimit(): void
$this->assertSame(Command::INVALID, $exitCode);
$this->assertStringContainsString('[ERROR] The step argument must be greater than 0.', $output);
+ $this->assertStringContainsString('Database connection: ' . $this->driverName, $output);
}
public function testWithoutNewMigrations(): void
@@ -123,6 +126,7 @@ public function testWithoutNewMigrations(): void
$this->assertSame(Command::FAILURE, $exitCode);
$this->assertStringContainsString('[WARNING] No new migrations found. Your system is up-to-date', $output);
+ $this->assertStringContainsString('Database connection: ' . $this->driverName, $output);
}
public function testCountMigrationsMoreLimit(): void
diff --git a/tests/Common/Command/AbstractUpdateCommandTest.php b/tests/Common/Command/AbstractUpdateCommandTest.php
index 8ca79c22..4c8bd09b 100644
--- a/tests/Common/Command/AbstractUpdateCommandTest.php
+++ b/tests/Common/Command/AbstractUpdateCommandTest.php
@@ -66,8 +66,12 @@ public function testExecuteWithPath(): void
// check title
$className = MigrationHelper::findMigrationClassNameInOutput($output);
+ $this->assertStringContainsString(">>> [OK] - '.Done..'.", $output);
+ $this->assertStringContainsString('Total 1 new migration to be applied:', $output);
+ $this->assertStringContainsString('Apply the above migration y/n:', $output);
$this->assertStringContainsString("Applying $className", $output);
$this->assertStringContainsString(">>> [OK] - Applied $className", $output);
+ $this->assertStringContainsString('>>> 1 Migration was applied.', $output);
}
public function testExecuteWithNamespace(): void
@@ -137,6 +141,7 @@ public function testExecuteExtended(): void
$command->setInputs(['yes']);
$exitCode = $command->execute([]);
+ $output = $command->getDisplay(true);
$db = $this->container->get(ConnectionInterface::class);
$dbSchema = $db->getSchema();
@@ -146,7 +151,9 @@ public function testExecuteExtended(): void
$this->assertSame(Command::SUCCESS, $exitCode);
/** Check create table department columns*/
- $this->assertCount(2, $departmentSchema->getColumns());
+ $this->assertSame(Command::SUCCESS, $exitCode);
+ $this->assertStringContainsString('Apply the above migrations y/n:', $output);
+ $this->assertStringContainsString('>>> 2 Migrations were applied.', $output);
/** Check table department field id */
$this->assertSame('id', $departmentSchema->getColumn('id')->getName());
@@ -226,6 +233,7 @@ public function testExecuteAgain(): void
$this->assertSame(Command::SUCCESS, $exitCode2);
$this->assertStringContainsString('No new migrations found.', $output2);
+ $this->assertStringContainsString('[OK] Your system is up-to-date.', $output2);
}
public function testNotMigrationInterface(): void
diff --git a/tests/Driver/Mssql/CreateCommandTest.php b/tests/Driver/Mssql/CreateCommandTest.php
index 7ec07a56..4da1d702 100644
--- a/tests/Driver/Mssql/CreateCommandTest.php
+++ b/tests/Driver/Mssql/CreateCommandTest.php
@@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MssqlFactory::createContainer();
+ $this->driverName = 'sqlsrv';
}
public function tearDown(): void
diff --git a/tests/Driver/Mssql/NewCommandTest.php b/tests/Driver/Mssql/NewCommandTest.php
index b4e0e799..b57a6580 100644
--- a/tests/Driver/Mssql/NewCommandTest.php
+++ b/tests/Driver/Mssql/NewCommandTest.php
@@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MssqlFactory::createContainer();
+ $this->driverName = 'sqlsrv';
}
public function tearDown(): void
diff --git a/tests/Driver/Mysql/CreateCommandTest.php b/tests/Driver/Mysql/CreateCommandTest.php
index 07ff8181..db3fa502 100644
--- a/tests/Driver/Mysql/CreateCommandTest.php
+++ b/tests/Driver/Mysql/CreateCommandTest.php
@@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MysqlFactory::createContainer();
+ $this->driverName = 'mysql';
}
public function tearDown(): void
diff --git a/tests/Driver/Mysql/NewCommandTest.php b/tests/Driver/Mysql/NewCommandTest.php
index 3243ccac..77e8fdfd 100644
--- a/tests/Driver/Mysql/NewCommandTest.php
+++ b/tests/Driver/Mysql/NewCommandTest.php
@@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MysqlFactory::createContainer();
+ $this->driverName = 'mysql';
}
public function tearDown(): void
diff --git a/tests/Driver/Oracle/CreateCommandTest.php b/tests/Driver/Oracle/CreateCommandTest.php
index 79e3e767..88a7d458 100644
--- a/tests/Driver/Oracle/CreateCommandTest.php
+++ b/tests/Driver/Oracle/CreateCommandTest.php
@@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = OracleFactory::createContainer();
+ $this->driverName = 'oci';
}
public function tearDown(): void
diff --git a/tests/Driver/Oracle/NewCommandTest.php b/tests/Driver/Oracle/NewCommandTest.php
index bf75bc7f..4356194d 100644
--- a/tests/Driver/Oracle/NewCommandTest.php
+++ b/tests/Driver/Oracle/NewCommandTest.php
@@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = OracleFactory::createContainer();
+ $this->driverName = 'oci';
}
public function tearDown(): void
diff --git a/tests/Driver/Pgsql/CreateCommandTest.php b/tests/Driver/Pgsql/CreateCommandTest.php
index 913ee5dd..3cda575b 100644
--- a/tests/Driver/Pgsql/CreateCommandTest.php
+++ b/tests/Driver/Pgsql/CreateCommandTest.php
@@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = PostgreSqlFactory::createContainer();
+ $this->driverName = 'pgsql';
}
public function tearDown(): void
diff --git a/tests/Driver/Pgsql/NewCommandTest.php b/tests/Driver/Pgsql/NewCommandTest.php
index a1a4a60a..5977f015 100644
--- a/tests/Driver/Pgsql/NewCommandTest.php
+++ b/tests/Driver/Pgsql/NewCommandTest.php
@@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = PostgreSqlFactory::createContainer();
+ $this->driverName = 'pgsql';
}
public function tearDown(): void
diff --git a/tests/Driver/Sqlite/CreateCommandTest.php b/tests/Driver/Sqlite/CreateCommandTest.php
index 832bf6bb..108a8649 100644
--- a/tests/Driver/Sqlite/CreateCommandTest.php
+++ b/tests/Driver/Sqlite/CreateCommandTest.php
@@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = SqLiteFactory::createContainer();
+ $this->driverName = 'sqlite';
}
public function tearDown(): void
diff --git a/tests/Driver/Sqlite/NewCommandTest.php b/tests/Driver/Sqlite/NewCommandTest.php
index 2cb28d2f..b87dfb4e 100644
--- a/tests/Driver/Sqlite/NewCommandTest.php
+++ b/tests/Driver/Sqlite/NewCommandTest.php
@@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = SqLiteFactory::createContainer();
+ $this->driverName = 'sqlite';
}
public function tearDown(): void