|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter 4 framework. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <admin@codeigniter.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace CodeIgniter\Commands; |
| 15 | + |
| 16 | +use CodeIgniter\Test\CIUnitTestCase; |
| 17 | +use CodeIgniter\Test\StreamFilterTrait; |
| 18 | +use PHPUnit\Framework\Attributes\Group; |
| 19 | + |
| 20 | +/** |
| 21 | + * @internal |
| 22 | + */ |
| 23 | +#[Group('Others')] |
| 24 | +final class CommandOverrideTest extends CIUnitTestCase |
| 25 | +{ |
| 26 | + use StreamFilterTrait; |
| 27 | + |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + $this->resetServices(); |
| 31 | + |
| 32 | + parent::setUp(); |
| 33 | + } |
| 34 | + |
| 35 | + protected function getBuffer(): string |
| 36 | + { |
| 37 | + return $this->getStreamFilterBuffer(); |
| 38 | + } |
| 39 | + |
| 40 | + public function testOverrideListCommands(): void |
| 41 | + { |
| 42 | + $this->copyListCommands(); |
| 43 | + |
| 44 | + command('list'); |
| 45 | + |
| 46 | + $this->assertStringContainsString('This is App\Commands\ListCommands', $this->getBuffer()); |
| 47 | + $this->assertStringNotContainsString('Displays basic usage information.', $this->getBuffer()); |
| 48 | + |
| 49 | + $this->deleteListCommands(); |
| 50 | + } |
| 51 | + |
| 52 | + private function copyListCommands(): void |
| 53 | + { |
| 54 | + if (! is_dir(APPPATH . 'Commands')) { |
| 55 | + mkdir(APPPATH . 'Commands'); |
| 56 | + } |
| 57 | + copy(SUPPORTPATH . '_command/ListCommands.php', APPPATH . 'Commands/ListCommands.php'); |
| 58 | + } |
| 59 | + |
| 60 | + private function deleteListCommands(): void |
| 61 | + { |
| 62 | + unlink(APPPATH . 'Commands/ListCommands.php'); |
| 63 | + } |
| 64 | +} |
0 commit comments