2016-09-11 18:24:04 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Tests\Wallabag\Command\Import;
|
2016-09-11 18:24:04 +00:00
|
|
|
|
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;
|
2022-08-28 14:59:43 +00:00
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception;
|
|
|
|
use Symfony\Component\Console\Exception\RuntimeException;
|
2016-09-11 18:24:04 +00:00
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2024-02-24 19:24:51 +00:00
|
|
|
use Tests\Wallabag\WallabagTestCase;
|
2016-09-11 18:24:04 +00:00
|
|
|
|
2024-02-24 19:24:51 +00:00
|
|
|
class RedisWorkerCommandTest extends WallabagTestCase
|
2016-09-11 18:24:04 +00:00
|
|
|
{
|
|
|
|
public function testRunRedisWorkerCommandWithoutArguments()
|
|
|
|
{
|
2022-08-28 14:59:43 +00:00
|
|
|
$this->expectException(RuntimeException::class);
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->expectExceptionMessage('Not enough arguments (missing: "serviceName")');
|
|
|
|
|
2022-11-23 16:09:32 +00:00
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
2016-09-11 18:24:04 +00:00
|
|
|
|
|
|
|
$command = $application->find('wallabag:import:redis-worker');
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
2022-09-03 00:28:07 +00:00
|
|
|
$tester->execute([]);
|
2016-09-11 18:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRedisWorkerCommandWithBadService()
|
|
|
|
{
|
2022-08-28 14:59:43 +00:00
|
|
|
$this->expectException(Exception::class);
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->expectExceptionMessage('No queue or consumer found for service name');
|
|
|
|
|
2022-11-23 16:09:32 +00:00
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
2016-09-11 18:24:04 +00:00
|
|
|
|
|
|
|
$command = $application->find('wallabag:import:redis-worker');
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'serviceName' => 'YOMONSERVICE',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRedisWorkerCommand()
|
|
|
|
{
|
2022-11-23 16:09:32 +00:00
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
2016-09-11 18:24:04 +00:00
|
|
|
|
|
|
|
$factory = new RedisMockFactory();
|
2022-09-01 18:54:56 +00:00
|
|
|
$redisMock = $factory->getAdapter(Client::class, true);
|
2016-09-11 18:24:04 +00:00
|
|
|
|
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([
|
|
|
|
'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
|
|
|
}
|
|
|
|
}
|