From 015c7a8359c950f9621b38b11c3973860a981da8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 20:24:04 +0200 Subject: Add more tests And ability to define how many messages can be hanle by the redis worker before stopping (usefull for tests) --- .../Command/RedisWorkerCommandTest.php | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php (limited to 'tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php') diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php new file mode 100644 index 00000000..74952847 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php @@ -0,0 +1,74 @@ +getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage No queue or consumer found for service name + */ + public function testRunRedisWorkerCommandWithBadService() + { + $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); + + $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock); + + // 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, + ]); + + $this->assertContains('Worker started at', $tester->getDisplay()); + $this->assertContains('Waiting for message', $tester->getDisplay()); + } +} -- cgit v1.2.3