Completed
Push — develop ( 7623eb...611a18 )
by Tom
03:37
created

ScriptCommandTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command;
4
5
class ScriptCommandTest extends TestCase
6
{
7
    public function testExecute()
8
    {
9
        $input = array(
10
            'command'  => 'script',
11
            'filename' => __DIR__ . '/_files/test.mr',
12
        );
13
14
        // Check pre defined vars
15
        $this->assertDisplayRegExp($input, '~^\Qmagento.root: \E/.+\R$~m');
16
        $this->assertDisplayRegExp($input, '~^\Qmagento.edition: \E(Community|Enterprise)\R$~m');
17
        $this->assertDisplayRegExp($input, '~^\Qmagento.version: \E\d\.\d+\.\d+\R$~m');
18
19
        $this->assertDisplayContains($input, 'magerun.version: ' . $this->getApplication()->getVersion());
0 ignored issues
show
Bug introduced by
The method getVersion 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
        $this->assertDisplayContains($input, 'code');
22
        $this->assertDisplayContains($input, 'foo.sql');
23
        $this->assertDisplayContains($input, 'BAR: foo.sql.gz');
24
        $this->assertDisplayContains($input, 'Magento Websites');
25
        $this->assertDisplayContains($input, 'web/secure/base_url');
26
        $this->assertDisplayContains($input, 'web/seo/use_rewrites => 1');
27
    }
28
}
29