├── tests ├── Support │ ├── Data │ │ └── .gitkeep │ ├── _generated │ │ └── .gitignore │ ├── CliTester.php │ └── UnitTester.php ├── Cli.suite.yml ├── Unit.suite.yml ├── Cli │ └── ConsoleCest.php └── Unit │ └── EchoCest.php ├── config ├── .gitignore ├── environments │ ├── dev │ │ └── params.php │ ├── prod │ │ └── params.php │ └── test │ │ └── params.php ├── commands.php ├── params.php └── di │ └── logger.php ├── runtime └── .gitignore ├── .env ├── .env.test ├── yii.bat ├── .editorconfig ├── .gitignore ├── yii ├── psalm.xml ├── codeception.yml ├── autoload.php ├── configuration.php ├── src └── Command │ └── EchoCommand.php └── composer.json /tests/Support/Data/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/.gitignore: -------------------------------------------------------------------------------- 1 | .merge-plan.php 2 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/Support/_generated/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | # Dev environment variables for Codeception. 2 | YII_ENV=dev 3 | YII_DEBUG=true 4 | -------------------------------------------------------------------------------- /.env.test: -------------------------------------------------------------------------------- 1 | # Test environment variables for Codeception. 2 | YII_ENV=test 3 | YII_DEBUG=true 4 | -------------------------------------------------------------------------------- /config/environments/dev/params.php: -------------------------------------------------------------------------------- 1 | EchoCommand::class, 9 | ]; 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 4 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | 16 | [*.yml] 17 | indent_size = 2 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # phpstorm project files 2 | .idea 3 | 4 | # netbeans project files 5 | nbproject 6 | 7 | # zend studio for eclipse project files 8 | .buildpath 9 | .project 10 | .settings 11 | 12 | # windows thumbnail cache 13 | Thumbs.db 14 | 15 | # Mac DS_Store Files 16 | .DS_Store 17 | 18 | # composer vendor dir 19 | /vendor 20 | -------------------------------------------------------------------------------- /config/params.php: -------------------------------------------------------------------------------- 1 | [ 7 | 'aliases' => [ 8 | '@root' => dirname(__DIR__), 9 | '@runtime' => '@root/runtime', 10 | ], 11 | ], 12 | 13 | 'yiisoft/yii-console' => [ 14 | 'commands' => require __DIR__ . '/commands.php', 15 | ], 16 | ]; 17 | -------------------------------------------------------------------------------- /config/di/logger.php: -------------------------------------------------------------------------------- 1 | [ 12 | 'class' => Logger::class, 13 | '__construct()' => [ 14 | 'targets' => ReferencesArray::from([FileTarget::class]), 15 | ], 16 | ], 17 | ]; 18 | -------------------------------------------------------------------------------- /yii: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 18 | -------------------------------------------------------------------------------- /psalm.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /codeception.yml: -------------------------------------------------------------------------------- 1 | namespace: App\Tests 2 | support_namespace: Support 3 | paths: 4 | tests: tests 5 | output: runtime/tests/_output 6 | data: tests/Support/Data 7 | support: tests/Support 8 | envs: tests/_envs 9 | actor_suffix: Tester 10 | extensions: 11 | enabled: 12 | - Codeception\Extension\RunFailed 13 | settings: 14 | suite_class: \PHPUnit_Framework_TestSuite 15 | memory_limit: 1024M 16 | colors: true 17 | coverage: 18 | enabled: true 19 | whitelist: 20 | include: 21 | - src/* 22 | params: 23 | - .env.test 24 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | load(); 11 | 12 | $_ENV['YII_ENV'] = empty($_ENV['YII_ENV']) ? null : (string)$_ENV['YII_ENV']; 13 | $_SERVER['YII_ENV'] = $_ENV['YII_ENV']; 14 | 15 | $_ENV['YII_DEBUG'] = filter_var( 16 | !empty($_ENV['YII_DEBUG']) ? $_ENV['YII_DEBUG'] : true, 17 | FILTER_VALIDATE_BOOLEAN, 18 | FILTER_NULL_ON_FAILURE 19 | ) ?? true; 20 | $_SERVER['YII_DEBUG'] = $_ENV['YII_DEBUG']; 21 | -------------------------------------------------------------------------------- /tests/Cli/ConsoleCest.php: -------------------------------------------------------------------------------- 1 | runShellCommand($command); 15 | $I->seeInShellOutput('Yii Console'); 16 | } 17 | 18 | public function testCommandHello(CliTester $I): void 19 | { 20 | $command = dirname(__DIR__, 2) . '/yii'; 21 | $I->runShellCommand($command . ' echo'); 22 | $I->seeInShellOutput('Hello!'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Support/CliTester.php: -------------------------------------------------------------------------------- 1 | [ 7 | 'params' => 'params.php', 8 | 'params-console' => '$params', 9 | 'di' => 'di/*.php', 10 | 'di-console' => '$di', 11 | 'di-delegates' => [], 12 | 'di-delegates-console' => '$di-delegates', 13 | 'di-providers' => [], 14 | 'di-providers-console' => '$di-providers', 15 | 'events' => [], 16 | 'events-console' => '$events', 17 | 'bootstrap' => [], 18 | 'bootstrap-console' => '$bootstrap', 19 | ], 20 | 'config-plugin-environments' => [ 21 | 'dev' => [ 22 | 'params' => [ 23 | 'environments/dev/params.php', 24 | ], 25 | ], 26 | 'prod' => [ 27 | 'params' => [ 28 | 'environments/prod/params.php', 29 | ], 30 | ], 31 | 'test' => [ 32 | 'params' => [ 33 | 'environments/test/params.php', 34 | ], 35 | ], 36 | ], 37 | 'config-plugin-options' => [ 38 | 'source-directory' => 'config', 39 | ], 40 | ]; 41 | -------------------------------------------------------------------------------- /src/Command/EchoCommand.php: -------------------------------------------------------------------------------- 1 | setDefinition( 26 | new InputDefinition([ 27 | new InputArgument($this->sentence, InputArgument::OPTIONAL, 'Sentence to say.', 'Hello!'), 28 | ]) 29 | ); 30 | } 31 | 32 | protected function execute(InputInterface $input, OutputInterface $output): int 33 | { 34 | $output->writeln("You said: {$input->getArgument('sentence')}"); 35 | 36 | return ExitCode::OK; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yiisoft/app-console", 3 | "type": "project", 4 | "description": "Template for console application", 5 | "keywords": [ 6 | "yii", 7 | "console", 8 | "application", 9 | "template" 10 | ], 11 | "homepage": "https://www.yiiframework.com/", 12 | "license": "BSD-3-Clause", 13 | "support": { 14 | "issues": "https://github.com/yiisoft/app-console/issues?state=open", 15 | "source": "https://github.com/yiisoft/app-console", 16 | "forum": "https://www.yiiframework.com/forum/", 17 | "wiki": "https://www.yiiframework.com/wiki/", 18 | "irc": "ircs://irc.libera.chat:6697/yii", 19 | "chat": "https://t.me/yii3en" 20 | }, 21 | "funding": [ 22 | { 23 | "type": "opencollective", 24 | "url": "https://opencollective.com/yiisoft" 25 | }, 26 | { 27 | "type": "github", 28 | "url": "https://github.com/sponsors/yiisoft" 29 | } 30 | ], 31 | "require": { 32 | "php": "^8.1", 33 | "vlucas/phpdotenv": "^5.3", 34 | "yiisoft/aliases": "^3.0", 35 | "yiisoft/log": "^2.0", 36 | "yiisoft/log-target-file": "^3.0", 37 | "yiisoft/yii-console": "^2.0", 38 | "yiisoft/yii-runner-console": "^2.0" 39 | }, 40 | "require-dev": { 41 | "codeception/codeception": "^5.0", 42 | "codeception/module-asserts": "^3.0", 43 | "codeception/module-cli": "^2.0", 44 | "codeception/module-phpbrowser": "^3.0", 45 | "vimeo/psalm": "^5.24" 46 | }, 47 | "autoload": { 48 | "psr-4": { 49 | "App\\": "src" 50 | } 51 | }, 52 | "autoload-dev": { 53 | "psr-4": { 54 | "App\\Tests\\": "tests" 55 | } 56 | }, 57 | "extra": { 58 | "config-plugin-file": "configuration.php" 59 | }, 60 | "config": { 61 | "sort-packages": true, 62 | "allow-plugins": { 63 | "infection/extension-installer": true, 64 | "composer/package-versions-deprecated": true, 65 | "yiisoft/config": true 66 | } 67 | }, 68 | "scripts": { 69 | "test": "codecept run" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/Unit/EchoCest.php: -------------------------------------------------------------------------------- 1 | config = $runner->getConfig(); 28 | $this->container = $runner->getContainer(); 29 | } 30 | 31 | public function testExecute(UnitTester $I): void 32 | { 33 | $app = new Application(); 34 | 35 | $params = $this->config->get('params'); 36 | 37 | $loader = new ContainerCommandLoader( 38 | $this->container, 39 | $params['yiisoft/yii-console']['commands'] 40 | ); 41 | 42 | $app->setCommandLoader($loader); 43 | 44 | $command = $app->find('echo'); 45 | 46 | $commandCreate = new CommandTester($command); 47 | 48 | $I->assertSame(ExitCode::OK, $commandCreate->execute([])); 49 | 50 | $output = $commandCreate->getDisplay(true); 51 | 52 | $I->assertStringContainsString('Hello!', $output); 53 | } 54 | 55 | public function testExecuteWithArgument(UnitTester $I): void 56 | { 57 | $app = new Application(); 58 | 59 | $params = $this->config->get('params'); 60 | 61 | $loader = new ContainerCommandLoader( 62 | $this->container, 63 | $params['yiisoft/yii-console']['commands'] 64 | ); 65 | 66 | $app->setCommandLoader($loader); 67 | 68 | $command = $app->find('echo'); 69 | 70 | $commandCreate = new CommandTester($command); 71 | 72 | $I->assertSame(ExitCode::OK, $commandCreate->execute(['sentence' => 'Foo!'])); 73 | 74 | $output = $commandCreate->getDisplay(true); 75 | 76 | $I->assertStringContainsString('Foo!', $output); 77 | } 78 | } 79 | --------------------------------------------------------------------------------