-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle the case where no items has been returned (#178)
Closes #176
- Loading branch information
Showing
5 changed files
with
156 additions
and
2 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
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
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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Webmozarts Console Parallelization package. | ||
* | ||
* (c) Webmozarts GmbH <office@webmozarts.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webmozarts\Console\Parallelization\Fixtures\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Webmozarts\Console\Parallelization\Fixtures\ItemNamingCapabilities; | ||
use Webmozarts\Console\Parallelization\ParallelCommand; | ||
use Webmozarts\Console\Parallelization\UnexpectedCall; | ||
|
||
final class NoItemCommand extends ParallelCommand | ||
{ | ||
use ItemNamingCapabilities; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct('test:no-item'); | ||
} | ||
|
||
protected function fetchItems(InputInterface $input, OutputInterface $output): iterable | ||
{ | ||
return []; | ||
} | ||
|
||
protected function runSingleCommand(string $item, InputInterface $input, OutputInterface $output): void | ||
{ | ||
throw UnexpectedCall::forMethod(__METHOD__); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Webmozarts Console Parallelization package. | ||
* | ||
* (c) Webmozarts GmbH <office@webmozarts.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webmozarts\Console\Parallelization\Fixtures; | ||
|
||
trait ItemNamingCapabilities | ||
{ | ||
/** | ||
* @param positive-int|0|null $count | ||
*/ | ||
protected function getItemName(?int $count): string | ||
{ | ||
if (null === $count) { | ||
return 'item(s)'; | ||
} | ||
|
||
return $count > 1 ? 'items' : 'item'; | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Webmozarts Console Parallelization package. | ||
* | ||
* (c) Webmozarts GmbH <office@webmozarts.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webmozarts\Console\Parallelization\Integration; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Webmozarts\Console\Parallelization\Fixtures\Command\NoItemCommand; | ||
|
||
/** | ||
* @coversNothing | ||
* | ||
* @internal | ||
*/ | ||
class NoItemCommandTest extends TestCase | ||
{ | ||
private Command $command; | ||
private CommandTester $commandTester; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->command = (new Application())->add(new NoItemCommand()); | ||
$this->commandTester = new CommandTester($this->command); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
unset($this->command, $this->commandTester); | ||
} | ||
|
||
public function test_it_can_execute_a_command_that_gives_no_item(): void | ||
{ | ||
$this->commandTester->execute( | ||
['command' => 'test:no-item'], | ||
['interactive' => true], | ||
); | ||
|
||
$expected = <<<'EOF' | ||
Processing 0 item in segments of 50, batches of 50, 1 round, 0 batch, with 1 child process. | ||
0 [>---------------------------] 10 secs 10.0 MiB | ||
// Memory usage: 10.0 MB (peak: 10.0 MB), time: 10 secs | ||
Processed 0 item. | ||
|
||
EOF; | ||
|
||
$actual = OutputNormalizer::removeIntermediateFixedProgressBars( | ||
$this->getOutput($this->commandTester), | ||
); | ||
|
||
self::assertSame($expected, $actual, $actual); | ||
} | ||
|
||
private function getOutput(CommandTester $commandTester): string | ||
{ | ||
$output = $commandTester->getDisplay(true); | ||
|
||
return OutputNormalizer::normalize($output); | ||
} | ||
} |