diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-11 20:24:04 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-11 22:15:31 +0200 |
commit | 015c7a8359c950f9621b38b11c3973860a981da8 (patch) | |
tree | c9564ff38242df100e19f2de77d8d640599c0ea2 /tests/Wallabag/ImportBundle/Command | |
parent | 7d862f83b95d24b4f081d73ca7b0bdf4435ae008 (diff) | |
download | wallabag-015c7a8359c950f9621b38b11c3973860a981da8.tar.gz wallabag-015c7a8359c950f9621b38b11c3973860a981da8.tar.zst wallabag-015c7a8359c950f9621b38b11c3973860a981da8.zip |
Add more tests
And ability to define how many messages can be hanle by the redis worker before stopping (usefull for tests)
Diffstat (limited to 'tests/Wallabag/ImportBundle/Command')
-rw-r--r-- | tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php | 74 |
1 files changed, 74 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Wallabag\ImportBundle\Command\RedisWorkerCommand; | ||
8 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
9 | use M6Web\Component\RedisMock\RedisMockFactory; | ||
10 | |||
11 | class RedisWorkerCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | /** | ||
14 | * @expectedException Symfony\Component\Console\Exception\RuntimeException | ||
15 | * @expectedExceptionMessage Not enough arguments (missing: "serviceName") | ||
16 | */ | ||
17 | public function testRunRedisWorkerCommandWithoutArguments() | ||
18 | { | ||
19 | $application = new Application($this->getClient()->getKernel()); | ||
20 | $application->add(new RedisWorkerCommand()); | ||
21 | |||
22 | $command = $application->find('wallabag:import:redis-worker'); | ||
23 | |||
24 | $tester = new CommandTester($command); | ||
25 | $tester->execute([ | ||
26 | 'command' => $command->getName(), | ||
27 | ]); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * @expectedException Symfony\Component\Config\Definition\Exception\Exception | ||
32 | * @expectedExceptionMessage No queue or consumer found for service name | ||
33 | */ | ||
34 | public function testRunRedisWorkerCommandWithBadService() | ||
35 | { | ||
36 | $application = new Application($this->getClient()->getKernel()); | ||
37 | $application->add(new RedisWorkerCommand()); | ||
38 | |||
39 | $command = $application->find('wallabag:import:redis-worker'); | ||
40 | |||
41 | $tester = new CommandTester($command); | ||
42 | $tester->execute([ | ||
43 | 'command' => $command->getName(), | ||
44 | 'serviceName' => 'YOMONSERVICE', | ||
45 | ]); | ||
46 | } | ||
47 | |||
48 | public function testRunRedisWorkerCommand() | ||
49 | { | ||
50 | $application = new Application($this->getClient()->getKernel()); | ||
51 | $application->add(new RedisWorkerCommand()); | ||
52 | |||
53 | $factory = new RedisMockFactory(); | ||
54 | $redisMock = $factory->getAdapter('Predis\Client', true); | ||
55 | |||
56 | $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock); | ||
57 | |||
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', '{}'); | ||
61 | |||
62 | $command = $application->find('wallabag:import:redis-worker'); | ||
63 | |||
64 | $tester = new CommandTester($command); | ||
65 | $tester->execute([ | ||
66 | 'command' => $command->getName(), | ||
67 | 'serviceName' => 'readability', | ||
68 | '--maxIterations' => 1, | ||
69 | ]); | ||
70 | |||
71 | $this->assertContains('Worker started at', $tester->getDisplay()); | ||
72 | $this->assertContains('Waiting for message', $tester->getDisplay()); | ||
73 | } | ||
74 | } | ||