|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\Tests\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Dtc\QueueBundle\Command\CreateJobCommand; |
|
6
|
|
|
use Dtc\QueueBundle\EventDispatcher\EventDispatcher; |
|
7
|
|
|
use Dtc\QueueBundle\Model\Job; |
|
8
|
|
|
use Dtc\QueueBundle\Model\JobTimingManager; |
|
9
|
|
|
use Dtc\QueueBundle\Model\Run; |
|
10
|
|
|
use Dtc\QueueBundle\Model\RunManager; |
|
11
|
|
|
use Dtc\QueueBundle\Model\WorkerManager; |
|
12
|
|
|
use Dtc\QueueBundle\Tests\FibonacciWorker; |
|
13
|
|
|
use Dtc\QueueBundle\Tests\StubJobManager; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
16
|
|
|
|
|
17
|
|
|
class CreateJobCommandTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
use CommandTrait; |
|
20
|
|
|
|
|
21
|
|
|
public function testCreateJobCommand() |
|
22
|
|
|
{ |
|
23
|
|
|
$jobTimingManager = new JobTimingManager(JobTimingManager::class, false); |
|
24
|
|
|
$runManager = new RunManager($jobTimingManager, Run::class); |
|
|
|
|
|
|
25
|
|
|
$jobManager = new StubJobManager($runManager, $jobTimingManager, Job::class); |
|
26
|
|
|
$container = new Container(); |
|
27
|
|
|
$container->set('dtc_queue.job_manager', $jobManager); |
|
28
|
|
|
$this->runCommandException(CreateJobCommand::class, $container, ['worker_name' => 'fibonacci', 'method' => 'fibonacci', 'args' => [1]]); |
|
29
|
|
|
|
|
30
|
|
|
$eventDispatcher = new EventDispatcher(); |
|
31
|
|
|
$workerManager = new WorkerManager($jobManager, $eventDispatcher); |
|
32
|
|
|
|
|
33
|
|
|
$container->set('dtc_queue.worker_manager', $workerManager); |
|
34
|
|
|
$this->runCommandException(CreateJobCommand::class, $container, ['worker_name' => 'fibonacci', 'method' => 'fibonacci', 'args' => [1]]); |
|
35
|
|
|
|
|
36
|
|
|
$worker = new FibonacciWorker(); |
|
37
|
|
|
$worker->setJobManager($jobManager); |
|
38
|
|
|
$workerManager->addWorker($worker); |
|
39
|
|
|
$this->runCommand(CreateJobCommand::class, $container, ['worker_name' => 'fibonacci', 'method' => 'fibonacci', 'args' => [1]]); |
|
40
|
|
|
|
|
41
|
|
|
self::assertTrue(isset($jobManager->calls['save'][0][0])); |
|
42
|
|
|
self::assertTrue($jobManager->calls['save'][0][0] instanceof Job); |
|
43
|
|
|
self::assertTrue(!isset($jobManager->calls['save'][0][1])); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.