2016-09-11 18:24:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Wallabag\ImportBundle\Command;
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
use M6Web\Component\RedisMock\RedisMockFactory;
|
2022-04-24 16:20:46 +00:00
|
|
|
use Predis\Client;
|
2016-09-11 18:24:04 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Wallabag\ImportBundle\Command\RedisWorkerCommand;
|
2016-09-11 18:24:04 +00:00
|
|
|
|
|
|
|
class RedisWorkerCommandTest extends WallabagCoreTestCase
|
|
|
|
{
|
|
|
|
public function testRunRedisWorkerCommandWithoutArguments()
|
|
|
|
{
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->expectException(\Symfony\Component\Console\Exception\RuntimeException::class);
|
|
|
|
$this->expectExceptionMessage('Not enough arguments (missing: "serviceName")');
|
|
|
|
|
2016-09-11 18:24:04 +00:00
|
|
|
$application = new Application($this->getClient()->getKernel());
|
|
|
|
$application->add(new RedisWorkerCommand());
|
|
|
|
|
|
|
|
$command = $application->find('wallabag:import:redis-worker');
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'command' => $command->getName(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRedisWorkerCommandWithBadService()
|
|
|
|
{
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->expectException(\Symfony\Component\Config\Definition\Exception\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No queue or consumer found for service name');
|
|
|
|
|
2016-09-11 18:24:04 +00:00
|
|
|
$application = new Application($this->getClient()->getKernel());
|
|
|
|
$application->add(new RedisWorkerCommand());
|
|
|
|
|
|
|
|
$command = $application->find('wallabag:import:redis-worker');
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'command' => $command->getName(),
|
|
|
|
'serviceName' => 'YOMONSERVICE',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRedisWorkerCommand()
|
|
|
|
{
|
|
|
|
$application = new Application($this->getClient()->getKernel());
|
|
|
|
$application->add(new RedisWorkerCommand());
|
|
|
|
|
|
|
|
$factory = new RedisMockFactory();
|
|
|
|
$redisMock = $factory->getAdapter('Predis\Client', true);
|
|
|
|
|
2022-04-24 16:20:46 +00:00
|
|
|
$application->getKernel()->getContainer()->set(Client::class, $redisMock);
|
2016-09-11 18:24:04 +00:00
|
|
|
|
|
|
|
// put a fake message in the queue so the worker will stop after reading that message
|
|
|
|
// instead of waiting for others
|
|
|
|
$redisMock->lpush('wallabag.import.readability', '{}');
|
|
|
|
|
|
|
|
$command = $application->find('wallabag:import:redis-worker');
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'command' => $command->getName(),
|
|
|
|
'serviceName' => 'readability',
|
|
|
|
'--maxIterations' => 1,
|
|
|
|
]);
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('Worker started at', $tester->getDisplay());
|
|
|
|
$this->assertStringContainsString('Waiting for message', $tester->getDisplay());
|
2016-09-11 18:24:04 +00:00
|
|
|
}
|
|
|
|
}
|