forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseCommandsTest.php
116 lines (92 loc) · 3.15 KB
/
DatabaseCommandsTest.php
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
108
109
110
111
112
113
114
115
116
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use PHPUnit\Framework\Attributes\Group;
/**
* @internal
*/
#[Group('DatabaseLive')]
final class DatabaseCommandsTest extends CIUnitTestCase
{
use StreamFilterTrait;
protected function tearDown(): void
{
command('migrate:rollback');
parent::tearDown();
}
protected function getBuffer(): string
{
return $this->getStreamFilterBuffer();
}
protected function clearBuffer(): void
{
$this->resetStreamFilterBuffer();
}
public function testMigrate(): void
{
command('migrate --all');
$this->assertStringContainsString('Migrations complete.', $this->getBuffer());
command('migrate:rollback');
$this->clearBuffer();
command('migrate -n Tests\\\\Support');
$this->assertStringContainsString('Migrations complete.', $this->getBuffer());
}
public function testMigrateRollbackValidBatchNumber(): void
{
command('migrate --all');
$this->clearBuffer();
command('migrate:rollback -b 1');
$this->assertStringContainsString('Done rolling back migrations.', $this->getBuffer());
}
public function testMigrateRollbackInvalidBatchNumber(): void
{
command('migrate --all');
$this->clearBuffer();
command('migrate:rollback -b x');
$this->assertStringContainsString('Invalid batch number: x', $this->getBuffer());
}
public function testMigrateRollback(): void
{
command('migrate --all -g tests');
$this->clearBuffer();
command('migrate:rollback -g tests');
$this->assertStringContainsString('Done rolling back migrations.', $this->getBuffer());
}
public function testMigrateRefresh(): void
{
command('migrate --all');
$this->clearBuffer();
command('migrate:refresh');
$this->assertStringContainsString('Migrations complete.', $this->getBuffer());
}
public function testMigrateStatus(): void
{
command('migrate --all');
$this->clearBuffer();
command('migrate:status -g tests');
$this->assertStringContainsString('Namespace', $this->getBuffer());
$this->assertStringContainsString('Version', $this->getBuffer());
$this->assertStringContainsString('Filename', $this->getBuffer());
}
public function testSeed(): void
{
command('migrate --all');
$this->clearBuffer();
// use '\\\\' to prevent escaping
command('db:seed Tests\\\\Support\\\\Database\\\\Seeds\\\\CITestSeeder');
$this->assertStringContainsString('Seeded', $this->getBuffer());
$this->clearBuffer();
command('db:seed Foobar.php');
$this->assertStringContainsString('The specified seeder is not a valid file:', $this->getBuffer());
}
}