Completed
Push — master ( a959b5...b73961 )
by Alejandro
28s queued 12s
created

MigrateDatabaseCommandTest::provideVerbosities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\CLI\Command\Db;
6
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Argument;
9
use Prophecy\Prophecy\ObjectProphecy;
10
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand;
11
use Symfony\Component\Console\Application;
12
use Symfony\Component\Console\Helper\ProcessHelper;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Console\Tester\CommandTester;
15
use Symfony\Component\Lock\Factory as Locker;
16
use Symfony\Component\Lock\LockInterface;
17
use Symfony\Component\Process\PhpExecutableFinder;
18
19
class MigrateDatabaseCommandTest extends TestCase
20
{
21
    /** @var CommandTester */
22
    private $commandTester;
23
    /** @var ObjectProphecy */
24
    private $processHelper;
25
26
    public function setUp(): void
27
    {
28
        $locker = $this->prophesize(Locker::class);
29
        $lock = $this->prophesize(LockInterface::class);
30
        $lock->acquire(Argument::any())->willReturn(true);
31
        $lock->release()->will(function () {
32
        });
33
        $locker->createLock(Argument::cetera())->willReturn($lock->reveal());
34
35
        $phpExecutableFinder = $this->prophesize(PhpExecutableFinder::class);
36
        $phpExecutableFinder->find(false)->willReturn('/usr/local/bin/php');
37
38
        $this->processHelper = $this->prophesize(ProcessHelper::class);
39
40
        $command = new MigrateDatabaseCommand(
41
            $locker->reveal(),
42
            $this->processHelper->reveal(),
43
            $phpExecutableFinder->reveal()
44
        );
45
        $app = new Application();
46
        $app->add($command);
47
48
        $this->commandTester = new CommandTester($command);
49
    }
50
51
    /** @test */
52
    public function migrationsCommandIsRunWithProperVerbosity(): void
53
    {
54
        $runCommand = $this->processHelper->mustRun(Argument::type(OutputInterface::class), [
55
            '/usr/local/bin/php',
56
            MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
57
            MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
58
        ], Argument::cetera());
59
60
        $this->commandTester->execute([]);
61
        $output = $this->commandTester->getDisplay();
62
63
        $this->assertStringContainsString('Migrating database...', $output);
64
        $this->assertStringContainsString('Database properly migrated!', $output);
65
        $runCommand->shouldHaveBeenCalledOnce();
66
    }
67
}
68