| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?php
- declare(strict_types=1);
- /**
- * CakePHP : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link https://cakephp.org CakePHP Project
- * @since 2.5.0
- * @license https://opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Command;
- use Cake\Console\CommandInterface;
- use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
- use Cake\Core\Configure;
- use Cake\Routing\Router;
- use Cake\TestSuite\TestCase;
- /**
- * CompletionCommandTest
- */
- class CompletionCommandTest extends TestCase
- {
- use ConsoleIntegrationTestTrait;
- /**
- * setUp method
- */
- public function setUp(): void
- {
- parent::setUp();
- static::setAppNamespace();
- Configure::write('Plugins.autoload', ['TestPlugin', 'TestPluginTwo']);
- }
- /**
- * tearDown
- */
- public function tearDown(): void
- {
- parent::tearDown();
- Router::reload();
- $this->clearPlugins();
- }
- /**
- * test that the startup method suppresses the command header
- */
- public function testStartup(): void
- {
- $this->exec('completion');
- $this->assertExitCode(CommandInterface::CODE_ERROR);
- $this->assertOutputNotContains('Welcome to CakePHP');
- }
- /**
- * test commands method that list all available commands
- */
- public function testCommands(): void
- {
- $this->exec('completion commands');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = [
- 'test_plugin.example',
- 'test_plugin.sample',
- 'test_plugin_two.example',
- 'unique',
- 'welcome',
- 'cache',
- 'help',
- 'i18n',
- 'plugin',
- 'routes',
- 'schema_cache',
- 'server',
- 'version',
- 'abort',
- 'auto_load_model',
- 'demo',
- 'integration',
- 'sample',
- ];
- foreach ($expected as $value) {
- $this->assertOutputContains($value);
- }
- }
- /**
- * test that options without argument returns nothing
- */
- public function testOptionsNoArguments(): void
- {
- $this->exec('completion options');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputEmpty();
- }
- /**
- * test that options with a nonexistent command returns nothing
- */
- public function testOptionsNonExistentCommand(): void
- {
- $this->exec('completion options foo');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputEmpty();
- }
- /**
- * test that options with an existing command returns the proper options
- */
- public function testOptionsCommand(): void
- {
- $this->exec('completion options schema_cache');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = [
- '--connection -c',
- '--help -h',
- '--quiet -q',
- '--verbose -v',
- ];
- foreach ($expected as $value) {
- $this->assertOutputContains($value);
- }
- }
- /**
- * test that options with an existing command / subcommand pair returns the proper options
- */
- public function testOptionsSubCommand(): void
- {
- $this->exec('completion options cache list');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = [
- '--help -h',
- '--quiet -q',
- '--verbose -v',
- ];
- foreach ($expected as $value) {
- $this->assertOutputContains($value);
- }
- }
- /**
- * test that nested command returns subcommand's options not command.
- */
- public function testOptionsNestedCommand(): void
- {
- $this->exec('completion options i18n extract');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = [
- '--plugin',
- '--app',
- ];
- foreach ($expected as $value) {
- $this->assertOutputContains($value);
- }
- }
- /**
- * test that subCommands with a existing CORE command returns the proper sub commands
- */
- public function testSubCommandsCorePlugin(): void
- {
- $this->exec('completion subcommands schema_cache');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = 'build clear';
- $this->assertOutputContains($expected);
- }
- /**
- * test that subCommands with a existing APP command returns the proper sub commands (in this case none)
- */
- public function testSubCommandsAppPlugin(): void
- {
- $this->exec('completion subcommands sample');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputContains('sub');
- }
- /**
- * test that subCommands with a existing CORE command
- */
- public function testSubCommandsCoreMultiwordCommand(): void
- {
- $this->exec('completion subcommands cache');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = [
- 'list', 'clear', 'clear_all',
- ];
- foreach ($expected as $value) {
- $this->assertOutputContains($value);
- }
- }
- /**
- * test that subCommands with an existing plugin command returns the proper sub commands
- * when the command name is unique and the dot notation not mandatory
- */
- public function testSubCommandsPlugin(): void
- {
- $this->exec('completion subcommands welcome');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = 'say_hello';
- $this->assertOutputContains($expected);
- }
- /**
- * test that using the dot notation when not mandatory works to provide backward compatibility
- */
- public function testSubCommandsPluginDotNotationBackwardCompatibility(): void
- {
- $this->exec('completion subcommands test_plugin_two.welcome');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = 'say_hello';
- $this->assertOutputContains($expected);
- }
- /**
- * test that subCommands with an app command that is also defined in a plugin and without the prefix "app."
- * returns proper sub commands
- */
- public function testSubCommandsAppDuplicatePluginNoDot(): void
- {
- $this->exec('completion subcommands sample');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputContains('sub');
- }
- /**
- * test that subCommands with a plugin command that is also defined in the returns proper sub commands
- */
- public function testSubCommandsPluginDuplicateApp(): void
- {
- $this->exec('completion subcommands test_plugin.sample');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = 'sub';
- $this->assertOutputContains($expected);
- }
- /**
- * test that subcommands without arguments returns nothing
- */
- public function testSubCommandsNoArguments(): void
- {
- $this->exec('completion subcommands');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputEmpty();
- }
- /**
- * test that subcommands with a nonexistent command returns nothing
- */
- public function testSubCommandsNonExistentCommand(): void
- {
- $this->exec('completion subcommands foo');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputEmpty();
- }
- /**
- * test that subcommands returns the available subcommands for the given command
- */
- public function testSubCommands(): void
- {
- $this->exec('completion subcommands schema_cache');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $expected = 'build clear';
- $this->assertOutputContains($expected);
- }
- /**
- * test that help returns content
- */
- public function testHelp(): void
- {
- $this->exec('completion --help');
- $this->assertExitCode(CommandInterface::CODE_SUCCESS);
- $this->assertOutputContains('Output a list of available commands');
- $this->assertOutputContains('Output a list of available sub-commands');
- }
- }
|