Skip to content

Commit

Permalink
Raise Mutation Test 100%. (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Aug 29, 2023
1 parent 7645468 commit aa0f671
Show file tree
Hide file tree
Showing 29 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/composer-require-checker.yml
Expand Up @@ -11,6 +11,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mariadb.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mssql.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mutation.yml
Expand Up @@ -38,7 +38,7 @@ jobs:
- ubuntu-latest

php:
- 8.1
- 8.0

services:
postgres:
Expand Down Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions .github/workflows/mysql.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/oracle.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pgsql.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sqlite.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static.yml
Expand Up @@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CreateCommand.php
Expand Up @@ -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.')
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DownCommand.php
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Command/HistoryCommand.php
Expand Up @@ -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);
}
Expand Down
13 changes: 5 additions & 8 deletions src/Command/NewCommand.php
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Yiisoft\Yii\Db\Migration\Service\MigrationService;

use function array_slice;
use function count;

/**
Expand All @@ -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');
Expand Down Expand Up @@ -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("<info>\t" . $migration . '</info>');
$output->writeln("<info>\t{$migration}</info>");
}

$this->migrationService->databaseConnection();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RedoCommand.php
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/Command/UpdateCommand.php
Expand Up @@ -40,20 +40,18 @@ 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');
}

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);

Expand Down
5 changes: 5 additions & 0 deletions tests/Common/Command/AbstractCreateCommandTest.php
Expand Up @@ -21,6 +21,7 @@ abstract class AbstractCreateCommandTest extends TestCase
use AssertTrait;

protected ContainerInterface $container;
protected string $driverName = '';

public function testCreateTableWithPath(): void
{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/Common/Command/AbstractNewCommandTest.php
Expand Up @@ -15,6 +15,7 @@
abstract class AbstractNewCommandTest extends TestCase
{
protected ContainerInterface $container;
protected string $driverName = '';

public function testExecuteWithNamespace(): void
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion tests/Common/Command/AbstractUpdateCommandTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Mssql/CreateCommandTest.php
Expand Up @@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MssqlFactory::createContainer();
$this->driverName = 'sqlsrv';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Mssql/NewCommandTest.php
Expand Up @@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MssqlFactory::createContainer();
$this->driverName = 'sqlsrv';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Mysql/CreateCommandTest.php
Expand Up @@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MysqlFactory::createContainer();
$this->driverName = 'mysql';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Mysql/NewCommandTest.php
Expand Up @@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = MysqlFactory::createContainer();
$this->driverName = 'mysql';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Oracle/CreateCommandTest.php
Expand Up @@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = OracleFactory::createContainer();
$this->driverName = 'oci';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Oracle/NewCommandTest.php
Expand Up @@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = OracleFactory::createContainer();
$this->driverName = 'oci';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Pgsql/CreateCommandTest.php
Expand Up @@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = PostgreSqlFactory::createContainer();
$this->driverName = 'pgsql';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Pgsql/NewCommandTest.php
Expand Up @@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = PostgreSqlFactory::createContainer();
$this->driverName = 'pgsql';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Sqlite/CreateCommandTest.php
Expand Up @@ -17,6 +17,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = SqLiteFactory::createContainer();
$this->driverName = 'sqlite';
}

public function tearDown(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Driver/Sqlite/NewCommandTest.php
Expand Up @@ -16,6 +16,7 @@ public function setUp(): void
{
parent::setUp();
$this->container = SqLiteFactory::createContainer();
$this->driverName = 'sqlite';
}

public function tearDown(): void
Expand Down

0 comments on commit aa0f671

Please sign in to comment.