|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Db; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Prophecy\Argument; |
|
8
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
9
|
|
|
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand; |
|
10
|
|
|
use Symfony\Component\Console\Application; |
|
11
|
|
|
use Symfony\Component\Console\Helper\ProcessHelper; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
14
|
|
|
use Symfony\Component\Lock\Factory as Locker; |
|
15
|
|
|
use Symfony\Component\Lock\LockInterface; |
|
16
|
|
|
use Symfony\Component\Process\PhpExecutableFinder; |
|
17
|
|
|
|
|
18
|
|
|
class MigrateDatabaseCommandTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var CommandTester */ |
|
21
|
|
|
private $commandTester; |
|
22
|
|
|
/** @var ObjectProphecy */ |
|
23
|
|
|
private $processHelper; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$locker = $this->prophesize(Locker::class); |
|
28
|
|
|
$lock = $this->prophesize(LockInterface::class); |
|
29
|
|
|
$lock->acquire(Argument::any())->willReturn(true); |
|
30
|
|
|
$lock->release()->will(function () { |
|
31
|
|
|
}); |
|
32
|
|
|
$locker->createLock(Argument::cetera())->willReturn($lock->reveal()); |
|
33
|
|
|
|
|
34
|
|
|
$phpExecutableFinder = $this->prophesize(PhpExecutableFinder::class); |
|
35
|
|
|
$phpExecutableFinder->find(false)->willReturn('/usr/local/bin/php'); |
|
36
|
|
|
|
|
37
|
|
|
$this->processHelper = $this->prophesize(ProcessHelper::class); |
|
38
|
|
|
|
|
39
|
|
|
$command = new MigrateDatabaseCommand( |
|
40
|
|
|
$locker->reveal(), |
|
41
|
|
|
$this->processHelper->reveal(), |
|
42
|
|
|
$phpExecutableFinder->reveal() |
|
43
|
|
|
); |
|
44
|
|
|
$app = new Application(); |
|
45
|
|
|
$app->add($command); |
|
46
|
|
|
|
|
47
|
|
|
$this->commandTester = new CommandTester($command); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
* @dataProvider provideVerbosities |
|
53
|
|
|
*/ |
|
54
|
|
|
public function migrationsCommandIsRunWithProperVerbosity(int $verbosity): void |
|
55
|
|
|
{ |
|
56
|
|
|
$runCommand = $this->processHelper->run(Argument::type(OutputInterface::class), [ |
|
57
|
|
|
'/usr/local/bin/php', |
|
58
|
|
|
MigrateDatabaseCommand::DOCTRINE_HELPER_SCRIPT, |
|
59
|
|
|
MigrateDatabaseCommand::DOCTRINE_HELPER_COMMAND, |
|
60
|
|
|
], null, null, $verbosity); |
|
61
|
|
|
|
|
62
|
|
|
$this->commandTester->execute([], [ |
|
63
|
|
|
'verbosity' => $verbosity, |
|
64
|
|
|
]); |
|
65
|
|
|
$output = $this->commandTester->getDisplay(); |
|
66
|
|
|
|
|
67
|
|
|
if ($verbosity >= OutputInterface::VERBOSITY_VERBOSE) { |
|
68
|
|
|
$this->assertStringContainsString('Migrating database...', $output); |
|
69
|
|
|
$this->assertStringContainsString('Database properly migrated!', $output); |
|
70
|
|
|
} |
|
71
|
|
|
$runCommand->shouldHaveBeenCalledOnce(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function provideVerbosities(): iterable |
|
75
|
|
|
{ |
|
76
|
|
|
yield 'debug' => [OutputInterface::VERBOSITY_DEBUG]; |
|
77
|
|
|
yield 'normal' => [OutputInterface::VERBOSITY_NORMAL]; |
|
78
|
|
|
yield 'quiet' => [OutputInterface::VERBOSITY_QUIET]; |
|
79
|
|
|
yield 'verbose' => [OutputInterface::VERBOSITY_VERBOSE]; |
|
80
|
|
|
yield 'very verbose' => [OutputInterface::VERBOSITY_VERY_VERBOSE]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|