forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowTableInfoMockIOTest.php
More file actions
86 lines (69 loc) · 2.08 KB
/
ShowTableInfoMockIOTest.php
File metadata and controls
86 lines (69 loc) · 2.08 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
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Database;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\Mock\MockInputOutput;
use PHPUnit\Framework\Attributes\Group;
/**
* @internal
*/
#[Group('DatabaseLive')]
final class ShowTableInfoMockIOTest extends CIUnitTestCase
{
use DatabaseTestTrait;
protected $migrateOnce = true;
protected function setUp(): void
{
parent::setUp();
CLI::reset();
putenv('NO_COLOR=1');
CLI::init();
}
protected function tearDown(): void
{
parent::tearDown();
CLI::reset();
putenv('NO_COLOR');
CLI::init();
}
public function testDbTableWithInputs(): void
{
// Set MockInputOutput to CLI.
$io = new MockInputOutput();
CLI::setInputOutput($io);
// User will input "a" (invalid value) and "0".
$io->setInputs(['a', '0']);
command('db:table');
$result = $io->getOutput();
$this->assertMatchesRegularExpression(
'/Which table do you want to see\? \[[\d,\s]+\]\: a/',
$result,
);
$this->assertMatchesRegularExpression(
'/The "Which table do you want to see\?" field must be one of: [\d,\s]+./',
$result,
);
$this->assertMatchesRegularExpression(
'/Which table do you want to see\? \[[\d,\s]+\]\: 0/',
$result,
);
$this->assertMatchesRegularExpression(
'/Data of Table "db_migrations"\:/',
$result,
);
$this->assertMatchesRegularExpression(
'/\| id[[:blank:]]+\| version[[:blank:]]+\| class[[:blank:]]+\| group[[:blank:]]+\| namespace[[:blank:]]+\| time[[:blank:]]+\| batch \|/',
$result,
);
}
}