2019-08-06 14:06:14 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2019-08-06 14:06:14 -05: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\Factory as Locker;
|
|
|
|
use Symfony\Component\Lock\LockInterface;
|
|
|
|
use Symfony\Component\Process\PhpExecutableFinder;
|
|
|
|
|
|
|
|
class MigrateDatabaseCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var CommandTester */
|
|
|
|
private $commandTester;
|
|
|
|
/** @var ObjectProphecy */
|
|
|
|
private $processHelper;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$locker = $this->prophesize(Locker::class);
|
|
|
|
$lock = $this->prophesize(LockInterface::class);
|
|
|
|
$lock->acquire(Argument::any())->willReturn(true);
|
|
|
|
$lock->release()->will(function () {
|
|
|
|
});
|
|
|
|
$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(),
|
|
|
|
$phpExecutableFinder->reveal()
|
|
|
|
);
|
|
|
|
$app = new Application();
|
|
|
|
$app->add($command);
|
|
|
|
|
|
|
|
$this->commandTester = new CommandTester($command);
|
|
|
|
}
|
|
|
|
|
2019-11-17 02:52:45 -06:00
|
|
|
/** @test */
|
|
|
|
public function migrationsCommandIsRunWithProperVerbosity(): void
|
2019-08-06 14:06:14 -05:00
|
|
|
{
|
2019-11-17 02:52:45 -06:00
|
|
|
$runCommand = $this->processHelper->mustRun(Argument::type(OutputInterface::class), [
|
2019-08-06 14:06:14 -05:00
|
|
|
'/usr/local/bin/php',
|
2019-11-17 02:52:45 -06:00
|
|
|
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
|
|
|
|
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
|
|
|
|
], Argument::cetera());
|
2019-08-06 14:06:14 -05:00
|
|
|
|
2019-11-17 02:52:45 -06:00
|
|
|
$this->commandTester->execute([]);
|
2019-08-06 14:06:14 -05:00
|
|
|
$output = $this->commandTester->getDisplay();
|
|
|
|
|
2019-11-17 02:52:45 -06:00
|
|
|
$this->assertStringContainsString('Migrating database...', $output);
|
|
|
|
$this->assertStringContainsString('Database properly migrated!', $output);
|
2019-08-06 14:06:14 -05:00
|
|
|
$runCommand->shouldHaveBeenCalledOnce();
|
|
|
|
}
|
|
|
|
}
|