Completed
Push — master ( 383d0c...3523cb )
by Tom
04:14
created

testShouldExecuteCorrectlyAndDisplaySuccessMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 15
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\System\Setup;
4
5
use Symfony\Component\Console\Tester\CommandTester;
6
use N98\Magento\Command\PHPUnit\TestCase;
7
8
class ChangeVersionCommandTest extends TestCase
9
{
10
    /**
11
     * @var ChangeVersionCommand;
12
     */
13
    protected $command;
14
15
    /**
16
     * @var CommandTester
17
     */
18
    protected $commandTester;
19
20
    /**
21
     * Set up the test dependencies
22
     */
23 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by
This method 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...
24
    {
25
        $application = $this->getApplication();
26
        $application->add(new ChangeVersionCommand());
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...
27
28
        $this->command = $this->getApplication()->find('sys:setup:change-version');
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...
29
30
        $this->commandTester = new CommandTester($this->command);
31
    }
32
33
    /**
34
     * Ensure that the version for a random Magento module can be changed
35
     */
36
    public function testShouldExecuteCorrectlyAndDisplaySuccessMessage()
37
    {
38
        $this->commandTester->execute(
39
            array(
40
                'command' => $this->command->getName(),
41
                'module'  => 'magento_customer',
42
                'version' => '2.0.0'
43
            )
44
        );
45
46
        $this->assertContains(
47
            'Successfully updated: "Magento_Customer"',
48
            $this->commandTester->getDisplay()
49
        );
50
    }
51
52
    /**
53
     * Ensure an exception is thrown when the module doesn't exist
54
     * @expectedException InvalidArgumentException
55
     */
56
    public function testExecuteShouldThrowExceptionWhenModuleDoesntExist()
57
    {
58
        $this->commandTester->execute(
59
            array(
60
                'command' => $this->command->getName(),
61
                'module'  => 'non_existent_module',
62
                'version' => '2.0.0'
63
            )
64
        );
65
    }
66
}
67