mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-28 00:38:46 +03:00
Migrated MigrateDatabaseCommandTest to use PHPUnit mocks
This commit is contained in:
parent
13431ff8cf
commit
101b4daff4
1 changed files with 19 additions and 24 deletions
|
@ -4,9 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace ShlinkioTest\Shlink\CLI\Command\Db;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand;
|
||||
use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface;
|
||||
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
||||
|
@ -21,45 +20,41 @@ class MigrateDatabaseCommandTest extends TestCase
|
|||
use CliTestUtilsTrait;
|
||||
|
||||
private CommandTester $commandTester;
|
||||
private ObjectProphecy $processHelper;
|
||||
private MockObject $processHelper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$locker = $this->prophesize(LockFactory::class);
|
||||
$lock = $this->prophesize(LockInterface::class);
|
||||
$lock->acquire(Argument::any())->willReturn(true);
|
||||
$lock->release()->will(function (): void {
|
||||
});
|
||||
$locker->createLock(Argument::cetera())->willReturn($lock->reveal());
|
||||
$locker = $this->createMock(LockFactory::class);
|
||||
$lock = $this->createMock(LockInterface::class);
|
||||
$lock->method('acquire')->withAnyParameters()->willReturn(true);
|
||||
$locker->method('createLock')->withAnyParameters()->willReturn($lock);
|
||||
|
||||
$phpExecutableFinder = $this->prophesize(PhpExecutableFinder::class);
|
||||
$phpExecutableFinder->find(false)->willReturn('/usr/local/bin/php');
|
||||
$phpExecutableFinder = $this->createMock(PhpExecutableFinder::class);
|
||||
$phpExecutableFinder->method('find')->with($this->isFalse())->willReturn('/usr/local/bin/php');
|
||||
|
||||
$this->processHelper = $this->prophesize(ProcessRunnerInterface::class);
|
||||
$this->processHelper = $this->createMock(ProcessRunnerInterface::class);
|
||||
|
||||
$command = new MigrateDatabaseCommand(
|
||||
$locker->reveal(),
|
||||
$this->processHelper->reveal(),
|
||||
$phpExecutableFinder->reveal(),
|
||||
);
|
||||
$command = new MigrateDatabaseCommand($locker, $this->processHelper, $phpExecutableFinder);
|
||||
$this->commandTester = $this->testerForCommand($command);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function migrationsCommandIsRunWithProperVerbosity(): void
|
||||
{
|
||||
$runCommand = $this->processHelper->run(Argument::type(OutputInterface::class), [
|
||||
'/usr/local/bin/php',
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
|
||||
'--no-interaction',
|
||||
]);
|
||||
$this->processHelper->expects($this->once())->method('run')->with(
|
||||
$this->isInstanceOf(OutputInterface::class),
|
||||
$this->equalTo([
|
||||
'/usr/local/bin/php',
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
|
||||
'--no-interaction',
|
||||
]),
|
||||
);
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
self::assertStringContainsString('Migrating database...', $output);
|
||||
self::assertStringContainsString('Database properly migrated!', $output);
|
||||
$runCommand->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue