blob: 749528478d470c8e20209b5769fe128a1c1ab89a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
namespace Tests\Wallabag\ImportBundle\Command;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Wallabag\ImportBundle\Command\RedisWorkerCommand;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use M6Web\Component\RedisMock\RedisMockFactory;
class RedisWorkerCommandTest extends WallabagCoreTestCase
{
/**
* @expectedException Symfony\Component\Console\Exception\RuntimeException
* @expectedExceptionMessage Not enough arguments (missing: "serviceName")
*/
public function testRunRedisWorkerCommandWithoutArguments()
{
$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(),
]);
}
/**
* @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());
}
}
|