-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathStatusCommandTest.php
More file actions
107 lines (90 loc) · 3.46 KB
/
StatusCommandTest.php
File metadata and controls
107 lines (90 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
declare(strict_types=1);
namespace Migrations\Test\TestCase\Command;
use Cake\Core\Exception\MissingPluginException;
use Migrations\Test\TestCase\TestCase;
use RuntimeException;
class StatusCommandTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->clearMigrationRecords('test');
}
public function testHelp(): void
{
$this->exec('migrations status --help');
$this->assertExitSuccess();
$this->assertOutputContains('command prints a list of all migrations');
$this->assertOutputContains('migrations status -c secondary');
}
public function testExecuteSimple(): void
{
$this->exec('migrations status -c test');
$this->assertExitSuccess();
// Check for table name info
$this->assertOutputContains('using migration table');
// Check for headers
$this->assertOutputContains('Status');
$this->assertOutputContains('Migration ID');
$this->assertOutputContains('Migration Name');
}
public function testExecuteSimpleJson(): void
{
$this->exec('migrations status -c test --format json');
$this->assertExitSuccess();
assert(isset($this->_out));
$output = $this->_out->messages();
$parsed = json_decode($output[0], true);
$this->assertTrue(is_array($parsed));
$this->assertCount(2, $parsed);
$this->assertArrayHasKey('id', $parsed[0]);
$this->assertArrayHasKey('status', $parsed[0]);
$this->assertArrayHasKey('name', $parsed[0]);
}
public function testExecutePlugin(): void
{
$this->loadPlugins(['Migrator']);
$this->exec('migrations status -c test -p Migrator');
$this->assertExitSuccess();
$this->assertOutputRegExp("/\|.*?down.*\|.*?Migrator.*?\|/");
}
public function testExecutePluginDoesNotExist(): void
{
$this->expectException(MissingPluginException::class);
$this->exec('migrations status -c test -p LolNope');
}
public function testExecuteConnectionDoesNotExist(): void
{
$this->expectException(RuntimeException::class);
$this->exec('migrations status -c lolnope');
}
public function testCleanNoMissingMigrations(): void
{
$this->exec('migrations status -c test --cleanup');
$this->assertExitSuccess();
$this->assertOutputContains('No missing migrations to clean up.');
}
public function testCleanWithMissingMigrations(): void
{
// Run a migration first to ensure the schema table exists
$this->exec('migrations migrate -c test --no-lock');
$this->assertExitSuccess();
// Insert a fake migration entry that doesn't exist in filesystem
$this->insertMigrationRecord('test', 99999999999999, 'FakeMissingMigration');
// Verify the fake migration is in the table
$initialCount = $this->getMigrationRecordCount('test');
$this->assertGreaterThan(0, $initialCount);
// Run the clean command
$this->exec('migrations status -c test --cleanup');
$this->assertExitSuccess();
$this->assertOutputContains('Removed 1 missing migration(s) from migration log.');
}
public function testCleanHelp(): void
{
$this->exec('migrations status --help');
$this->assertExitSuccess();
$this->assertOutputContains('--cleanup');
$this->assertOutputContains('Remove MISSING migrations from the');
}
}