JobFailedEventTest::testEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SfCod\QueueBundle\Tests\Event;
4
5
use Exception;
6
use PHPUnit\Framework\TestCase;
7
use SfCod\QueueBundle\Event\JobFailedEvent;
8
use SfCod\QueueBundle\Job\JobContractInterface;
9
use Symfony\Contracts\EventDispatcher\Event;
10
11
/**
12
 * Class JobFailedEventTest
13
 *
14
 * @author Virchenko Maksim <[email protected]>
15
 *
16
 * @package SfCod\QueueBundle\Tests\Event
17
 */
18
class JobFailedEventTest extends TestCase
19
{
20
    /**
21
     * Test event
22
     */
23
    public function testEvent()
24
    {
25
        $message = uniqid('message_');
26
        $connectionName = uniqid('connection_');
27
        $job = $this->createMock(JobContractInterface::class);
28
        $exception = new Exception($message);
29
30
        $event = new JobFailedEvent($connectionName, $job, $exception);
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...
31
32
        self::assertInstanceOf(Event::class, $event);
33
        self::assertEquals($connectionName, $event->getConnectionName());
34
        self::assertEquals($job, $event->getJob());
35
        self::assertEquals($exception, $event->getException());
36
        self::assertEquals($exception->getMessage(), $event->getException()->getMessage());
37
    }
38
}
39