|
24 | 24 | use CodeIgniter\Test\Mock\MockInputOutput; |
25 | 25 | use CodeIgniter\Test\StreamFilterTrait; |
26 | 26 | use PHPUnit\Framework\Attributes\CoversClass; |
| 27 | +use PHPUnit\Framework\Attributes\DataProvider; |
27 | 28 | use PHPUnit\Framework\Attributes\Group; |
28 | 29 |
|
29 | 30 | /** |
@@ -99,6 +100,70 @@ public function testHeaderDoesNotShowOnNoHeader(): void |
99 | 100 | ); |
100 | 101 | } |
101 | 102 |
|
| 103 | + #[DataProvider('provideHeaderlessCommandOmitsHeader')] |
| 104 | + public function testHeaderlessCommandOmitsHeader(string $command): void |
| 105 | + { |
| 106 | + $this->initializeConsole($command); |
| 107 | + (new Console())->run(); |
| 108 | + |
| 109 | + $this->assertSame( |
| 110 | + <<<'EOT' |
| 111 | +
|
| 112 | + Ran test:headerless. |
| 113 | + |
| 114 | + EOT, |
| 115 | + $this->getStreamFilterBuffer(), |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * @return iterable<string, array{string}> |
| 121 | + */ |
| 122 | + public static function provideHeaderlessCommandOmitsHeader(): iterable |
| 123 | + { |
| 124 | + yield 'name' => ['test:headerless']; |
| 125 | + |
| 126 | + yield 'alias' => ['test:quiet']; |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @param list<string> $tokens |
| 131 | + */ |
| 132 | + #[DataProvider('provideHelpForHeaderlessCommandShowsHeader')] |
| 133 | + public function testHelpForHeaderlessCommandShowsHeader(array $tokens): void |
| 134 | + { |
| 135 | + $this->initializeConsole(...$tokens); |
| 136 | + (new Console())->run(); |
| 137 | + |
| 138 | + $this->assertStringContainsString( |
| 139 | + sprintf('CodeIgniter v%s Command Line Tool', CodeIgniter::CI_VERSION), |
| 140 | + $this->getStreamFilterBuffer(), |
| 141 | + ); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @return iterable<string, array{list<string>}> |
| 146 | + */ |
| 147 | + public static function provideHelpForHeaderlessCommandShowsHeader(): iterable |
| 148 | + { |
| 149 | + yield 'help command' => [['help', 'test:headerless']]; |
| 150 | + |
| 151 | + yield 'help option' => [['test:headerless', '--help']]; |
| 152 | + |
| 153 | + yield 'help shortcut on alias' => [['test:quiet', '-h']]; |
| 154 | + } |
| 155 | + |
| 156 | + public function testNoHeaderOptionAppliesAlongsideHelpOption(): void |
| 157 | + { |
| 158 | + $this->initializeConsole('env', '--help', '--no-header'); |
| 159 | + (new Console())->run(); |
| 160 | + |
| 161 | + $this->assertStringNotContainsString( |
| 162 | + sprintf('CodeIgniter v%s Command Line Tool', CodeIgniter::CI_VERSION), |
| 163 | + $this->getStreamFilterBuffer(), |
| 164 | + ); |
| 165 | + } |
| 166 | + |
102 | 167 | public function testRun(): void |
103 | 168 | { |
104 | 169 | $this->initializeConsole(); |
|
0 commit comments