-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?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 App\Commands; | ||
|
||
use CodeIgniter\CLI\CLI; | ||
use CodeIgniter\Commands\ListCommands as BaseListCommands; | ||
|
||
class ListCommands extends BaseListCommands | ||
{ | ||
/** | ||
* The group the command is lumped under | ||
* when listing commands. | ||
* | ||
* @var string | ||
*/ | ||
protected $group = 'App'; | ||
|
||
/** | ||
* The Command's name | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'list'; | ||
|
||
/** | ||
* the Command's short description | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'This is testing to override `list` command.'; | ||
|
||
/** | ||
* the Command's usage | ||
* | ||
* @var string | ||
*/ | ||
protected $usage = 'list'; | ||
|
||
/** | ||
* Displays the help for the spark cli script itself. | ||
*/ | ||
public function run(array $params) | ||
{ | ||
CLI::write('This is '.__CLASS__); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?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('Others')] | ||
final class CommandOverrideTest extends CIUnitTestCase | ||
{ | ||
use StreamFilterTrait; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->resetServices(); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
protected function getBuffer() | ||
{ | ||
return $this->getStreamFilterBuffer(); | ||
} | ||
|
||
public function testOverrideListCommands(): void | ||
{ | ||
$this->copyListCommands(); | ||
|
||
command('list'); | ||
|
||
$this->assertStringContainsString('This is App\Commands\ListCommands', $this->getBuffer()); | ||
$this->assertStringNotContainsString('Displays basic usage information.', $this->getBuffer()); | ||
|
||
$this->deleteListCommands(); | ||
} | ||
|
||
private function copyListCommands(): void | ||
{ | ||
if (! is_dir(APPPATH . 'Commands')) { | ||
mkdir(APPPATH . 'Commands'); | ||
} | ||
copy(SUPPORTPATH . '_command/ListCommands.php', APPPATH . 'Commands/ListCommands.php'); | ||
} | ||
|
||
private function deleteListCommands(): void | ||
{ | ||
unlink(APPPATH . 'Commands/ListCommands.php'); | ||
} | ||
} |