WorkerHelperFactoryTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * Aist Queue (http://mateuszsitek.com/projects/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\Queue\Console\Helper;
11
12
use Aist\Queue\Console\Helper\WorkerHelper;
13
use Aist\Queue\Console\Helper\WorkerHelperFactory;
14
use Interop\Container\ContainerInterface;
15
use PHPUnit\Framework\TestCase;
16
use Prophecy\Prophecy\ProphecyInterface;
17
use SlmQueue\Worker\WorkerInterface;
18
use SlmQueueDoctrine\Worker\DoctrineWorker;
19
20 View Code Duplication
class WorkerHelperFactoryTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    /**
23
     * @var ContainerInterface|ProphecyInterface
24
     */
25
    private $container;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function setUp()
31
    {
32
        $this->container = $this->prophesize(ContainerInterface::class);
33
34
        $worker = $this->prophesize(WorkerInterface::class);
35
        $this->container->get(DoctrineWorker::class)->willReturn($worker);
36
    }
37
38
    public function testCallingFactoryReturnsHelperInstance()
39
    {
40
        $factory = new WorkerHelperFactory();
41
        $this->assertInstanceOf(WorkerHelperFactory::class, $factory);
42
43
        $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...
44
45
        $this->assertInstanceOf(WorkerHelper::class, $class);
46
    }
47
}
48