Completed
Push — master ( 29ee36...16ede1 )
by Tom
03:58
created

DeleteCommandTest::testExecute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 65
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 9.3571
c 0
b 0
f 0
cc 3
eloc 38
nc 4
nop 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A DeleteCommandTest::deleteAll() 0 22 2
A DeleteCommandTest::getStores() 0 9 1
A DeleteCommandTest::deleteOne() 15 15 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace N98\Magento\Command\Config;
4
5
use N98\Magento\Command\TestCase;
6
7
class DeleteCommandTest extends TestCase
8
{
9
    /**
10
     * @test
11
     */
12 View Code Duplication
    public function deleteOne()
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...
13
    {
14
        $input = array(
15
            'command' => 'config:set',
16
            'path'    => 'n98_magerun/foo/bar',
17
            'value'   => '1234',
18
        );
19
        $this->assertDisplayContains($input, 'n98_magerun/foo/bar => 1234');
20
21
        $input = array(
22
            'command' => 'config:delete',
23
            'path'    => 'n98_magerun/foo/bar',
24
        );
25
        $this->assertDisplayContains($input, '| n98_magerun/foo/bar | default | 0  |');
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function deleteAll()
32
    {
33
        $input = array(
34
            'command'    => 'config:set',
35
            'path'       => 'n98_magerun/foo/bar',
36
            '--scope'    => 'stores',
37
            '--scope-id' => null, # placeholder
38
            'value'      => 'fake-value',
39
        );
40
41
        foreach ($this->getStores() as $store) {
42
            $input['--scope-id'] = $store->getId();
43
            $this->assertDisplayContains($input, "n98_magerun/foo/bar => fake-value");
44
        }
45
46
        $input = array(
47
            'command' => 'config:delete',
48
            'path'    => 'n98_magerun/foo/bar',
49
            '--all'   => true,
50
        );
51
        $this->assertDisplayContains($input, '| n98_magerun/foo/bar | stores   |');
52
    }
53
54
    /**
55
     * @return array|\Magento\Store\Api\Data\StoreInterface[]
56
     */
57
    private function getStores()
58
    {
59
        $application = $this->getApplication();
60
61
        /* @var $storeManager \Magento\Store\Model\StoreManager */
62
        $storeManager = $application->getObjectManager()->get('Magento\Store\Model\StoreManager');
0 ignored issues
show
Bug introduced by
The method getObjectManager 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...
63
64
        return $storeManager->getStores();
65
    }
66
}
67