ListCommandTest::testExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\System\Url;
4
5
use Symfony\Component\Console\Tester\CommandTester;
6
use N98\Magento\Command\PHPUnit\TestCase;
7
8
class ListCommandTest extends TestCase
9
{
10
    
11
    public function testExecute()
12
    {
13
        $application = $this->getApplication();
14
        $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...
15
        $command = $this->getApplication()->find('sys:url: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...
16
17
        $commandTester = new CommandTester($command);
18
        $commandTester->execute(
19
            array(
20
                'command'          => $command->getName(),
21
                'stores'           => 0, // admin store
22
                'linetemplate'     => 'prefix {url} suffix',
23
                '--add-categories' => true,
24
                '--add-products'   => true,
25
                '--add-cmspages'   => true,
26
            )
27
        );
28
29
        $this->assertRegExp('/prefix/', $commandTester->getDisplay());
30
        $this->assertRegExp('/http/', $commandTester->getDisplay());
31
        $this->assertRegExp('/suffix/', $commandTester->getDisplay());
32
    }
33
}
34