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

DeleteCommandTest::deleteAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 2
eloc 15
nc 2
nop 0
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
    public function deleteOne()
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