SendJobFactoryTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * Mailer Queue Component (http://mateuszsitek.com/projects/mailer-component-queue)
5
 *
6
 * @copyright Copyright (c) 2017 DIGITAL WOLVES LTD (http://digitalwolves.ltd) All rights reserved.
7
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
8
 */
9
10
namespace Test\Aist\Mailer\Component\Queue\Job;
11
12
use Aist\Mailer\Component\Queue\Job\SendJob;
13
use Aist\Mailer\Component\Queue\Job\SendJobFactory;
14
use Interop\Container\ContainerInterface;
15
use PHPUnit\Framework\TestCase;
16
use Prophecy\Prophecy\ProphecyInterface;
17
use Psr\Log\LoggerInterface;
18
use Zend\Mail\Transport\TransportInterface;
19
20
class SendJobFactoryTest extends TestCase
21
{
22
    /**
23
     * @var ContainerInterface|ProphecyInterface
24
     */
25
    private $container;
26
27
    /** @inheritdoc */
28
    public function setUp()
29
    {
30
        $this->container = $this->prophesize(ContainerInterface::class);
31
32
        $mailer = $this->prophesize(TransportInterface::class);
33
        $this->container->get('mailer')->willReturn($mailer);
34
35
        $logger = $this->prophesize(LoggerInterface::class);
36
        $this->container->get(LoggerInterface::class)->willReturn($logger);
37
    }
38
39
    public function testCallingFactoryReturnsJobInstance()
40
    {
41
        $factory = new SendJobFactory();
42
        $this->assertInstanceOf(SendJobFactory::class, $factory);
43
44
        $class = $factory($this->container->reveal());
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ProphecyInterface, but not in Interop\Container\ContainerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
45
46
        $this->assertInstanceOf(SendJob::class, $class);
47
    }
48
}
49