3 namespace Tests\Wallabag\ImportBundle\Command
;
5 use M6Web\Component\RedisMock\RedisMockFactory
;
6 use Symfony\Bundle\FrameworkBundle\Console\Application
;
7 use Symfony\Component\Console\Tester\CommandTester
;
8 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
9 use Wallabag\ImportBundle\Command\RedisWorkerCommand
;
11 class RedisWorkerCommandTest
extends WallabagCoreTestCase
14 * @expectedException \Symfony\Component\Console\Exception\RuntimeException
15 * @expectedExceptionMessage Not enough arguments (missing: "serviceName")
17 public function testRunRedisWorkerCommandWithoutArguments()
19 $application = new Application($this->getClient()->getKernel());
20 $application->add(new RedisWorkerCommand());
22 $command = $application->find('wallabag:import:redis-worker');
24 $tester = new CommandTester($command);
26 'command' => $command->getName(),
31 * @expectedException \Symfony\Component\Config\Definition\Exception\Exception
32 * @expectedExceptionMessage No queue or consumer found for service name
34 public function testRunRedisWorkerCommandWithBadService()
36 $application = new Application($this->getClient()->getKernel());
37 $application->add(new RedisWorkerCommand());
39 $command = $application->find('wallabag:import:redis-worker');
41 $tester = new CommandTester($command);
43 'command' => $command->getName(),
44 'serviceName' => 'YOMONSERVICE',
48 public function testRunRedisWorkerCommand()
50 $application = new Application($this->getClient()->getKernel());
51 $application->add(new RedisWorkerCommand());
53 $factory = new RedisMockFactory();
54 $redisMock = $factory->getAdapter('Predis\Client', true);
56 $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock);
58 // put a fake message in the queue so the worker will stop after reading that message
59 // instead of waiting for others
60 $redisMock->lpush('wallabag.import.readability', '{}');
62 $command = $application->find('wallabag:import:redis-worker');
64 $tester = new CommandTester($command);
66 'command' => $command->getName(),
67 'serviceName' => 'readability',
68 '--maxIterations' => 1,
71 $this->assertContains('Worker started at', $tester->getDisplay());
72 $this->assertContains('Waiting for message', $tester->getDisplay());