Passed
Pull Request — master (#57)
by Matthew
15:03
created

CreateJobCommandTest::testCreateJobCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
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\Manager\JobTimingManager;
9
use Dtc\QueueBundle\Model\Run;
10
use Dtc\QueueBundle\Manager\RunManager;
11
use Dtc\QueueBundle\Manager\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);
0 ignored issues
show
Unused Code introduced by
The call to Dtc\QueueBundle\Manager\RunManager::__construct() has too many arguments starting with Dtc\QueueBundle\Model\Run::class. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $runManager = /** @scrutinizer ignore-call */ new RunManager($jobTimingManager, Run::class);

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. Please note the @ignore annotation hint above.

Loading history...
25
        $jobManager = new StubJobManager($runManager, $jobTimingManager, Job::class);
26
        $container = new Container();
27
        $container->set('dtc_queue.manager.job', $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.manager.worker', $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