Completed
Push — master ( 6764cb...4e8215 )
by Christian
03:24 queued 11s
created

CreateCommandTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testExecute() 0 14 1
1
<?php
2
3
namespace N98\Magento\Command\Admin\Token;
4
5
use N98\Magento\Command\TestCase;
6
use Symfony\Component\Console\Tester\CommandTester;
7
8
/**
9
 * Class CreateCommandTest
10
 * @package N98\Magento\Command\Admin\Token
11
 */
12
class CreateCommandTest extends TestCase
13
{
14
    public function testExecute()
15
    {
16
        $command = $this->getApplication()->find('admin:token:create');
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...
17
18
        $commandTester = new CommandTester($command);
19
        $commandTester->execute([
20
            'username'     => 'admin',
21
            '--no-newline' => true,
22
        ]);
23
24
        $output = $commandTester->getDisplay();
25
        $this->assertNotEmpty($output);
26
        $this->assertEquals(32, strlen($output));
27
    }
28
}
29