Completed
Push — master ( 5017d8...561e2a )
by Christian
07:36 queued 03:33
created

DiCommandTest::runsInProductionMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Config\Data;
4
5
use Magento\Deploy\Model\Mode;
6
use Magento\Framework\App\State;
7
use N98\Magento\Command\TestCase;
8
use Symfony\Component\Console\Input\ArgvInput;
9
use Symfony\Component\Console\Output\ConsoleOutput;
10
use Symfony\Component\Console\Tester\CommandTester;
11
12
class DiCommandTest extends TestCase
13
{
14
    /**
15
     * @return void
16
     */
17
    protected function setUp()
18
    {
19
        if ($this->runsInProductionMode()) {
20
            $this->markTestSkipped('This command is not available in production mode');
21
        }
22
23
        parent::setUp();
24
    }
25
26
    /**
27
     * @return bool
28
     */
29 View Code Duplication
    private function runsInProductionMode()
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...
30
    {
31
        $objectManager = $this->getApplication()->getObjectManager();
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...
32
        $mode = $objectManager->create(
33
            Mode::class,
34
            [
35
                'input'  => new ArgvInput(),
36
                'output' => new ConsoleOutput(),
37
            ]
38
        );
39
40
        return $mode->getMode() === State::MODE_PRODUCTION;
41
    }
42
43
    /**
44
     * @test
45
     * @outputBuffering off
46
     */
47
    public function itShouldLoadPrimaryConfig()
48
    {
49
        $command = $this->getApplication()->find('config:data:di');
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...
50
51
        $commandTester = new CommandTester($command);
52
        $commandTester->execute(
53
            [
54
                'command' => 'config:data:di',
55
            ]
56
        );
57
58
        $this->assertContains('LoggerInterface', $commandTester->getDisplay());
59
    }
60
61
    /**
62
     * @test
63
     * @outputBuffering off
64
     */
65 View Code Duplication
    public function itShouldLoadGlobalConfigScope()
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...
66
    {
67
        $command = $this->getApplication()->find('config:data:di');
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...
68
69
        $commandTester = new CommandTester($command);
70
        $commandTester->execute(
71
            [
72
                'command' => 'config:data:di',
73
                '--scope' => 'global',
74
            ]
75
        );
76
77
        $this->assertContains('Magento\Catalog\Api\Data\ProductInterface', $commandTester->getDisplay());
78
    }
79
80
    /**
81
     * @test
82
     * @outputBuffering off
83
     */
84 View Code Duplication
    public function itShouldLoadFrontendConfigScope()
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...
85
    {
86
        $command = $this->getApplication()->find('config:data:di');
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...
87
88
        $commandTester = new CommandTester($command);
89
        $commandTester->execute(
90
            [
91
                'command' => 'config:data:dump',
92
                '--scope' => 'frontend',
93
                'type'    => '\Magento\Framework\App\FrontControllerInterface',
94
            ]
95
        );
96
97
        $this->assertContains('Magento\Framework\App\FrontController', $commandTester->getDisplay());
98
    }
99
}
100