-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCommandTest.php
More file actions
136 lines (105 loc) · 3.9 KB
/
CommandTest.php
File metadata and controls
136 lines (105 loc) · 3.9 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?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;
use CodeIgniter\CLI\Commands;
use CodeIgniter\Log\Logger;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use PHPUnit\Framework\Attributes\Group;
use Tests\Support\Commands\AppInfo;
/**
* @internal
*/
#[Group('Others')]
final class CommandTest extends CIUnitTestCase
{
use StreamFilterTrait;
private Logger $logger;
private Commands $commands;
protected function setUp(): void
{
$this->resetServices();
parent::setUp();
$this->logger = service('logger');
$this->commands = service('commands');
}
protected function getBuffer(): string
{
return $this->getStreamFilterBuffer();
}
public function testListCommands(): void
{
command('list');
// make sure the result looks like a command list
$this->assertStringContainsString('Lists the available commands.', $this->getBuffer());
$this->assertStringContainsString('Displays basic usage information.', $this->getBuffer());
}
public function testListCommandsSimple(): void
{
command('list --simple');
$this->assertStringContainsString('db:seed', $this->getBuffer());
$this->assertStringNotContainsString('Lists the available commands.', $this->getBuffer());
}
public function testCustomCommand(): void
{
command('app:info');
$this->assertStringContainsString('CodeIgniter Version:', $this->getBuffer());
}
public function testShowError(): void
{
command('app:info');
$commands = $this->commands->getCommands();
/** @var AppInfo */
$command = new $commands['app:info']['class']($this->logger, $this->commands);
$command->helpMe();
$this->assertStringContainsString('Displays basic usage information.', $this->getBuffer());
}
public function testCommandCall(): void
{
command('app:info');
$commands = $this->commands->getCommands();
/** @var AppInfo */
$command = new $commands['app:info']['class']($this->logger, $this->commands);
$command->bomb();
$this->assertStringContainsString('Invalid "background" color:', $this->getBuffer());
}
public function testAbstractCommand(): void
{
command('app:pablo');
$this->assertStringContainsString('not found', $this->getBuffer());
}
public function testNamespacesCommand(): void
{
command('namespaces');
$this->assertStringContainsString('| Namespace', $this->getBuffer());
$this->assertStringContainsString('| Config', $this->getBuffer());
$this->assertStringContainsString('| Yes', $this->getBuffer());
}
public function testInexistentCommandWithNoAlternatives(): void
{
command('app:oops');
$this->assertStringContainsString('Command "app:oops" not found', $this->getBuffer());
}
public function testInexistentCommandsButWithOneAlternative(): void
{
command('namespace');
$this->assertStringContainsString('Command "namespace" not found.', $this->getBuffer());
$this->assertStringContainsString('Did you mean this?', $this->getBuffer());
$this->assertStringContainsString('namespaces', $this->getBuffer());
}
public function testInexistentCommandsButWithManyAlternatives(): void
{
command('clear');
$this->assertStringContainsString('Command "clear" not found.', $this->getBuffer());
$this->assertStringContainsString('Did you mean one of these?', $this->getBuffer());
$this->assertStringContainsString(':clear', $this->getBuffer());
}
}