|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\Tests\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Dtc\QueueBundle\DependencyInjection\Compiler\WorkerCompilerPass; |
|
6
|
|
|
use Dtc\QueueBundle\EventDispatcher\EventDispatcher; |
|
7
|
|
|
use Dtc\QueueBundle\Model\WorkerManager; |
|
8
|
|
|
use Dtc\QueueBundle\ODM\JobManager; |
|
9
|
|
|
use Dtc\QueueBundle\ODM\RunManager; |
|
10
|
|
|
use Dtc\QueueBundle\Tests\FibonacciWorker; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
14
|
|
|
|
|
15
|
|
|
class WorkerCompilerPassTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
protected function getBaseContainer() |
|
18
|
|
|
{ |
|
19
|
|
|
$container = new ContainerBuilder(); |
|
20
|
|
|
|
|
21
|
|
|
$count = count($container->getDefinitions()); |
|
22
|
|
|
$compilerPass = new WorkerCompilerPass(); |
|
23
|
|
|
$compilerPass->process($container); |
|
24
|
|
|
self::assertEquals($count, count($container->getDefinitions())); |
|
25
|
|
|
|
|
26
|
|
|
$container = new ContainerBuilder(); |
|
27
|
|
|
$definition1 = new Definition(); |
|
28
|
|
|
$definition1->setClass(WorkerManager::class); |
|
29
|
|
|
$container->setParameter('dtc_queue.default_manager', 'odm'); |
|
30
|
|
|
$container->setParameter('dtc_queue.run_manager', 'odm'); |
|
31
|
|
|
$container->setParameter('dtc_queue.class_job', null); |
|
32
|
|
|
$container->setParameter('dtc_queue.class_job_archive', null); |
|
33
|
|
|
$container->setParameter('dtc_queue.document_manager', 'default'); |
|
34
|
|
|
$container->setParameter('dtc_queue.entity_manager', 'default'); |
|
35
|
|
|
$definition2 = new Definition(); |
|
36
|
|
|
$definition2->setClass(JobManager::class); |
|
37
|
|
|
$definition3 = new Definition(); |
|
38
|
|
|
$definition3->setClass(RunManager::class); |
|
39
|
|
|
$definition4 = new Definition(); |
|
40
|
|
|
$definition4->setClass(EventDispatcher::class); |
|
41
|
|
|
$container->addDefinitions([ |
|
42
|
|
|
'dtc_queue.worker_manager' => $definition1, |
|
43
|
|
|
'dtc_queue.job_manager.odm' => $definition2, |
|
44
|
|
|
'dtc_queue.run_manager.odm' => $definition3, |
|
45
|
|
|
'dtc_queue.event_dispatcher' => $definition4, |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
return $container; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testProcess() |
|
52
|
|
|
{ |
|
53
|
|
|
$container = $this->getBaseContainer(); |
|
54
|
|
|
$count = count($container->getAliases()); |
|
55
|
|
|
$compilerPass = new WorkerCompilerPass(); |
|
56
|
|
|
$compilerPass->process($container); |
|
57
|
|
|
|
|
58
|
|
|
self::assertNotEquals($count, count($container->getAliases())); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testProcessInvalidWorker() |
|
62
|
|
|
{ |
|
63
|
|
|
$container = $this->getBaseContainer(); |
|
64
|
|
|
$definition5 = new Definition(); |
|
65
|
|
|
$definition5->setClass(JobManager::class); |
|
66
|
|
|
$definition5->addTag('dtc_queue.worker'); |
|
67
|
|
|
$container->addDefinitions(['some.worker' => $definition5]); |
|
68
|
|
|
|
|
69
|
|
|
$count = count($container->getAliases()); |
|
70
|
|
|
$compilerPass = new WorkerCompilerPass(); |
|
71
|
|
|
$failed = false; |
|
72
|
|
|
try { |
|
73
|
|
|
$compilerPass->process($container); |
|
74
|
|
|
$failed = true; |
|
75
|
|
|
} catch (\Exception $e) { |
|
76
|
|
|
self::assertTrue(true); |
|
77
|
|
|
} |
|
78
|
|
|
self::assertFalse($failed); |
|
79
|
|
|
self::assertNotEquals($count, count($container->getAliases())); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testProcessValidWorker() |
|
83
|
|
|
{ |
|
84
|
|
|
$container = $this->getBaseContainer(); |
|
85
|
|
|
$definition5 = new Definition(); |
|
86
|
|
|
$definition5->setClass(FibonacciWorker::class); |
|
87
|
|
|
$definition5->addTag('dtc_queue.worker'); |
|
88
|
|
|
$container->addDefinitions(['some.worker' => $definition5]); |
|
89
|
|
|
|
|
90
|
|
|
$count = count($container->getAliases()); |
|
91
|
|
|
$compilerPass = new WorkerCompilerPass(); |
|
92
|
|
|
$compilerPass->process($container); |
|
93
|
|
|
self::assertNotEquals($count, count($container->getAliases())); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|