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;
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2022-10-22 14:08:05 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-08-06 22:06:14 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand;
|
2021-02-13 00:59:40 +03:00
|
|
|
use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface;
|
2023-06-18 11:51:59 +03:00
|
|
|
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
|
2019-08-06 22:06:14 +03:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2019-11-30 19:59:04 +03:00
|
|
|
use Symfony\Component\Lock\LockFactory;
|
2024-02-17 12:46:29 +03:00
|
|
|
use Symfony\Component\Lock\SharedLockInterface;
|
2019-08-06 22:06:14 +03:00
|
|
|
use Symfony\Component\Process\PhpExecutableFinder;
|
|
|
|
|
|
|
|
class MigrateDatabaseCommandTest extends TestCase
|
|
|
|
{
|
2019-12-30 00:27:00 +03:00
|
|
|
private CommandTester $commandTester;
|
2022-10-24 20:53:13 +03:00
|
|
|
private MockObject & ProcessRunnerInterface $processHelper;
|
2019-08-06 22:06:14 +03:00
|
|
|
|
2022-09-11 13:02:49 +03:00
|
|
|
protected function setUp(): void
|
2019-08-06 22:06:14 +03:00
|
|
|
{
|
2022-10-22 14:08:05 +03:00
|
|
|
$locker = $this->createMock(LockFactory::class);
|
2024-02-17 12:46:29 +03:00
|
|
|
$lock = $this->createMock(SharedLockInterface::class);
|
2022-10-22 14:08:05 +03:00
|
|
|
$lock->method('acquire')->withAnyParameters()->willReturn(true);
|
|
|
|
$locker->method('createLock')->withAnyParameters()->willReturn($lock);
|
2019-08-06 22:06:14 +03:00
|
|
|
|
2022-10-22 14:08:05 +03:00
|
|
|
$phpExecutableFinder = $this->createMock(PhpExecutableFinder::class);
|
|
|
|
$phpExecutableFinder->method('find')->with($this->isFalse())->willReturn('/usr/local/bin/php');
|
2019-08-06 22:06:14 +03:00
|
|
|
|
2022-10-22 14:08:05 +03:00
|
|
|
$this->processHelper = $this->createMock(ProcessRunnerInterface::class);
|
2019-08-06 22:06:14 +03:00
|
|
|
|
2022-10-22 14:08:05 +03:00
|
|
|
$command = new MigrateDatabaseCommand($locker, $this->processHelper, $phpExecutableFinder);
|
2023-06-18 11:51:59 +03:00
|
|
|
$this->commandTester = CliTestUtils::testerForCommand($command);
|
2019-08-06 22:06:14 +03:00
|
|
|
}
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test]
|
2019-11-17 11:52:45 +03:00
|
|
|
public function migrationsCommandIsRunWithProperVerbosity(): void
|
2019-08-06 22:06:14 +03:00
|
|
|
{
|
2022-10-23 19:15:57 +03:00
|
|
|
$this->processHelper->expects($this->once())->method('run')->with($this->isInstanceOf(OutputInterface::class), [
|
|
|
|
'/usr/local/bin/php',
|
|
|
|
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
|
|
|
|
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
|
|
|
|
'--no-interaction',
|
|
|
|
]);
|
2019-08-06 22:06:14 +03:00
|
|
|
|
2019-11-17 11:52:45 +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
|
|
|
}
|
|
|
|
}
|