shlink/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php

68 lines
2.3 KiB
PHP
Raw Normal View History

2019-08-06 22:06:14 +03:00
<?php
2019-10-05 18:26:10 +03:00
2019-08-06 22:06:14 +03:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Db;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Lock\LockFactory;
2019-08-06 22:06:14 +03:00
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
2019-08-06 22:06:14 +03:00
class MigrateDatabaseCommandTest extends TestCase
{
2019-12-30 00:27:00 +03:00
private CommandTester $commandTester;
private ObjectProphecy $processHelper;
2019-08-06 22:06:14 +03:00
public function setUp(): void
{
$locker = $this->prophesize(LockFactory::class);
2019-08-06 22:06:14 +03:00
$lock = $this->prophesize(LockInterface::class);
$lock->acquire(Argument::any())->willReturn(true);
2020-01-01 22:48:31 +03:00
$lock->release()->will(function (): void {
2019-08-06 22:06:14 +03:00
});
$locker->createLock(Argument::cetera())->willReturn($lock->reveal());
$phpExecutableFinder = $this->prophesize(PhpExecutableFinder::class);
$phpExecutableFinder->find(false)->willReturn('/usr/local/bin/php');
$this->processHelper = $this->prophesize(ProcessHelper::class);
$command = new MigrateDatabaseCommand(
$locker->reveal(),
$this->processHelper->reveal(),
2020-01-01 22:48:31 +03:00
$phpExecutableFinder->reveal(),
2019-08-06 22:06:14 +03:00
);
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
}
/** @test */
public function migrationsCommandIsRunWithProperVerbosity(): void
2019-08-06 22:06:14 +03:00
{
$runCommand = $this->processHelper->mustRun(Argument::type(OutputInterface::class), [
2019-08-06 22:06:14 +03:00
'/usr/local/bin/php',
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
'--no-interaction',
], Argument::cetera())->willReturn(new Process([]));
2019-08-06 22:06:14 +03:00
$this->commandTester->execute([]);
2019-08-06 22:06:14 +03:00
$output = $this->commandTester->getDisplay();
2020-10-04 01:35:14 +03:00
self::assertStringContainsString('Migrating database...', $output);
self::assertStringContainsString('Database properly migrated!', $output);
2019-08-06 22:06:14 +03:00
$runCommand->shouldHaveBeenCalledOnce();
}
}