1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace App\Tests\Unit; |
||
6 | |||
7 | use App\Tests\Support\UnitTester; |
||
8 | use Psr\Container\ContainerInterface; |
||
9 | use Symfony\Component\Console\Application; |
||
10 | use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; |
||
11 | use Symfony\Component\Console\Tester\CommandTester; |
||
12 | use Yiisoft\Config\ConfigInterface; |
||
13 | use Yiisoft\Yii\Console\ExitCode; |
||
14 | |||
15 | use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner; |
||
16 | |||
17 | use function dirname; |
||
18 | |||
19 | final class HelloCest |
||
20 | { |
||
21 | private ContainerInterface $container; |
||
22 | private ConfigInterface $config; |
||
23 | |||
24 | public function _before(UnitTester $I): void |
||
0 ignored issues
–
show
|
|||
25 | { |
||
26 | $runner = new ConsoleApplicationRunner( |
||
27 | rootPath: dirname(__DIR__, 2), |
||
28 | debug: false, |
||
29 | checkEvents: false, |
||
30 | ); |
||
31 | $this->config = $runner->getConfig(); |
||
32 | $this->container = $runner->getContainer(); |
||
33 | } |
||
34 | |||
35 | public function testExecute(UnitTester $I): void |
||
36 | { |
||
37 | $app = new Application(); |
||
38 | $params = $this->config->get('params-console'); |
||
39 | |||
40 | $loader = new ContainerCommandLoader( |
||
41 | $this->container, |
||
42 | $params['yiisoft/yii-console']['commands'] |
||
43 | ); |
||
44 | |||
45 | $app->setCommandLoader($loader); |
||
46 | |||
47 | $command = $app->find('hello'); |
||
48 | |||
49 | $commandCreate = new CommandTester($command); |
||
50 | |||
51 | $commandCreate->setInputs(['yes']); |
||
52 | |||
53 | $I->assertSame(ExitCode::OK, $commandCreate->execute([])); |
||
54 | |||
55 | $output = $commandCreate->getDisplay(true); |
||
56 | |||
57 | $I->assertStringContainsString('Hello!', $output); |
||
58 | } |
||
59 | } |
||
60 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.