JobProcessTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 6
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGetProcess() 0 32 1
1
<?php
2
3
namespace SfCod\QueueBundle\Tests\Service;
4
5
use PHPUnit\Framework\TestCase;
6
use SfCod\QueueBundle\Job\JobContractInterface;
7
use SfCod\QueueBundle\Service\JobProcess;
8
use SfCod\QueueBundle\Worker\Options;
9
10
/**
11
 * Class JobProcessTest
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package SfCod\QueueBundle\Tests\Service
16
 */
17
class JobProcessTest extends TestCase
18
{
19
    /**
20
     * Test get process
21
     */
22
    public function testGetProcess()
23
    {
24
        $scriptName = uniqid('script_');
25
        $binPath = __DIR__;
26
27
        $jobProcess = new JobProcess($scriptName, $binPath);
28
29
        $jobId = uniqid('id_');
30
        $jobQueue = uniqid('queue_');
31
32
        $job = $this->createMock(JobContractInterface::class);
33
        $job
34
            ->expects(self::exactly(2))
35
            ->method('getJobId')
36
            ->willReturn($jobId);
37
        $job
38
            ->expects(self::exactly(2))
39
            ->method('getQueue')
40
            ->willReturn($jobQueue);
41
42
        $connectionName = uniqid('connection_');
43
44
        $job
45
            ->method('getConnectionName')
46
            ->willReturn($connectionName);
47
48
        $process = $jobProcess->getProcess($job, new Options());
0 ignored issues
show
Documentation introduced by
$job is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<SfCod\QueueBundle...b\JobContractInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
50
        $command = sprintf('%s %s job-queue:run-job %s --connection=%s --queue=%s --env=%s --delay=0 --memory=128 --timeout=60 --sleep=3 --maxTries=0 > /dev/null 2>&1 &', 'php', $binPath . DIRECTORY_SEPARATOR . $scriptName, $job->getJobId(), $connectionName, $job->getQueue(), 'prod');
51
52
        self::assertEquals($command, $process->getCommandLine());
53
    }
54
}
55