ListCommandTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace N98\Magento\Command\Cache;
3
4
use Symfony\Component\Console\Tester\CommandTester;
5
use N98\Magento\Command\PHPUnit\TestCase;
6
7
class ListCommandTest extends TestCase
8
{
9
    /**
10
     * @var $command ListCommand
11
     */
12
    protected $command = null;
13
14
    public function setUp()
15
    {
16
        $application = $this->getApplication();
17
        $application->add(new ListCommand);
0 ignored issues
show
Bug introduced by
The method add does only exist in N98\Magento\Application, but not in PHPUnit_Framework_MockObject_MockObject.

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...
18
19
        $this->command = $this->getApplication()->find('cache:list');
0 ignored issues
show
Bug introduced by
The method find does only exist in N98\Magento\Application, but not in PHPUnit_Framework_MockObject_MockObject.

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...
20
    }
21
22
    /**
23
     * Test whether the $cacheTypes property is getting filled
24
     */
25
    public function testTypesIsNotEmpty()
26
    {
27
        $commandTester = new CommandTester($this->command);
28
        $commandTester->execute(array('command' => $this->command->getName()));
29
30
        $this->assertNotEmpty($this->command->getTypes());
31
    }
32
33
    /**
34
     * Test whether only enabled cache types are taken into account when --enabled=1
35
     */
36
    public function testEnabledFilter()
37
    {
38
        $commandTester = new CommandTester($this->command);
39
        $commandTester->execute(array('command' => $this->command->getName(), '--enabled' => 1));
40
41
        $cacheTypes = $this->command->getTypes();
42
        $disabledCacheTypes = 0;
43
44
        foreach ($cacheTypes as $cacheType) {
45
            if (!$cacheType->getStatus()) {
46
                $disabledCacheTypes++;
47
            }
48
        }
49
50
        $this->assertEquals(0, $disabledCacheTypes);
51
    }
52
}
53