Skip to content

Commit 9928cca

Browse files
Improve test coverage (#237)
1 parent dddf279 commit 9928cca

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
<source>
2929
<include>
3030
<directory suffix=".php">./src</directory>
31-
<directory suffix=".php">./config</directory>
3231
</include>
32+
<exclude>
33+
<directory suffix=".php">./config</directory>
34+
</exclude>
3335
</source>
3436
</phpunit>

src/Command/ListenAllCommand.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public function __construct(
3030
parent::__construct();
3131
}
3232

33+
/**
34+
* @codeCoverageIgnore
35+
*/
3336
public function configure(): void
3437
{
3538
$this->addArgument(
@@ -65,18 +68,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6568
$queues[] = $this->queueProvider->get($channel);
6669
}
6770

71+
$pauseSeconds = (int) $input->getOption('pause');
72+
if ($pauseSeconds < 0) {
73+
$pauseSeconds = 1;
74+
}
75+
6876
while ($this->loop->canContinue()) {
6977
$hasMessages = false;
7078
foreach ($queues as $queue) {
7179
$hasMessages = $queue->run((int) $input->getOption('maximum')) > 0 || $hasMessages;
7280
}
7381

7482
if (!$hasMessages) {
75-
$pauseSeconds = (int) $input->getOption('pause');
76-
if ($pauseSeconds < 0) {
77-
$pauseSeconds = 1;
78-
}
79-
8083
/** @psalm-var 0|positive-int $pauseSeconds */
8184
sleep($pauseSeconds);
8285
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Queue\Tests\Unit\Command;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Console\Input\ArrayInput;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Yiisoft\Queue\Cli\LoopInterface;
11+
use Yiisoft\Queue\Command\ListenAllCommand;
12+
use Yiisoft\Queue\Provider\QueueProviderInterface;
13+
use Yiisoft\Queue\QueueInterface;
14+
15+
final class ListenAllCommandTest extends TestCase
16+
{
17+
public function testExecute(): void
18+
{
19+
$queue1 = $this->createMock(QueueInterface::class);
20+
$queue1->expects($this->once())->method('run');
21+
$queue2 = $this->createMock(QueueInterface::class);
22+
$queue2->expects($this->once())->method('run');
23+
24+
$queueFactory = $this->createMock(QueueProviderInterface::class);
25+
$queueFactory->method('get')->willReturn($queue1, $queue2);
26+
27+
$loop = $this->createMock(LoopInterface::class);
28+
$loop->method('canContinue')->willReturn(true, false);
29+
30+
31+
$command = new ListenAllCommand(
32+
$queueFactory,
33+
$loop,
34+
['channel1', 'channel2'],
35+
);
36+
$input = new ArrayInput([], $command->getNativeDefinition());
37+
$input->setOption('pause', 0);
38+
$exitCode = $command->run($input, $this->createMock(OutputInterface::class));
39+
40+
$this->assertEquals(0, $exitCode);
41+
}
42+
}

0 commit comments

Comments
 (0)