|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Webmozarts Console Parallelization package. |
| 5 | + * |
| 6 | + * (c) Webmozarts GmbH <office@webmozarts.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace Webmozarts\Console\Parallelization\Integration; |
| 15 | + |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use Symfony\Component\Console\Application; |
| 18 | +use Symfony\Component\Console\Command\Command; |
| 19 | +use Symfony\Component\Console\Tester\CommandTester; |
| 20 | +use Webmozarts\Console\Parallelization\Fixtures\Command\NoItemCommand; |
| 21 | + |
| 22 | +/** |
| 23 | + * @coversNothing |
| 24 | + * |
| 25 | + * @internal |
| 26 | + */ |
| 27 | +class NoItemCommandTest extends TestCase |
| 28 | +{ |
| 29 | + private Command $command; |
| 30 | + private CommandTester $commandTester; |
| 31 | + |
| 32 | + protected function setUp(): void |
| 33 | + { |
| 34 | + $this->command = (new Application())->add(new NoItemCommand()); |
| 35 | + $this->commandTester = new CommandTester($this->command); |
| 36 | + } |
| 37 | + |
| 38 | + protected function tearDown(): void |
| 39 | + { |
| 40 | + unset($this->command, $this->commandTester); |
| 41 | + } |
| 42 | + |
| 43 | + public function test_it_can_execute_a_command_that_gives_no_item(): void |
| 44 | + { |
| 45 | + $this->commandTester->execute( |
| 46 | + ['command' => 'test:no-item'], |
| 47 | + ['interactive' => true], |
| 48 | + ); |
| 49 | + |
| 50 | + $expected = <<<'EOF' |
| 51 | + Processing 0 item in segments of 50, batches of 50, 1 round, 0 batch, with 1 child process. |
| 52 | +
|
| 53 | + 0 [>---------------------------] 10 secs 10.0 MiB |
| 54 | +
|
| 55 | + // Memory usage: 10.0 MB (peak: 10.0 MB), time: 10 secs |
| 56 | +
|
| 57 | + Processed 0 item. |
| 58 | + |
| 59 | + EOF; |
| 60 | + |
| 61 | + $actual = OutputNormalizer::removeIntermediateFixedProgressBars( |
| 62 | + $this->getOutput($this->commandTester), |
| 63 | + ); |
| 64 | + |
| 65 | + self::assertSame($expected, $actual, $actual); |
| 66 | + } |
| 67 | + |
| 68 | + private function getOutput(CommandTester $commandTester): string |
| 69 | + { |
| 70 | + $output = $commandTester->getDisplay(true); |
| 71 | + |
| 72 | + return OutputNormalizer::normalize($output); |
| 73 | + } |
| 74 | +} |
0 commit comments