Completed
Push — develop ( bbf1d7...d89cb9 )
by Tom
05:51
created

CheckTablesCommandTest::getCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Database\Maintain;
4
5
use N98\Magento\Command\PHPUnit\TestCase;
6
use Symfony\Component\Console\Tester\CommandTester;
7
8
/**
9
 * @see \N98\Magento\Command\Database\Maintain\CheckTablesCommand
10
 */
11
class CheckTablesCommandTest extends TestCase
12
{
13
    public function testExecuteMyIsam()
14
    {
15
        $this->markTestSkipped('Currently we have no myisam tables in a magento2 installation');
16
17
        $command = $this->getCommand();
18
19
        $commandTester = new CommandTester($command);
20
        $commandTester->execute(
21
            array(
22
                'command'  => $command->getName(),
23
                '--format' => 'csv',
24
                '--type'   => 'quick',
25
                '--table'  => 'oauth_nonce',
26
            )
27
        );
28
        $this->assertContains('oauth_nonce,check,quick,OK', $commandTester->getDisplay());
29
    }
30
31
    public function testExecuteInnoDb()
32
    {
33
        $command = $this->getCommand();
34
35
        $commandTester = new CommandTester($command);
36
        $commandTester->execute(
37
            array(
38
                'command'  => $command->getName(),
39
                '--format' => 'csv',
40
                '--type'   => 'quick',
41
                '--table'  => 'catalog_product_entity_media_gallery*',
42
            )
43
        );
44
        $timeRegex = '"\s+[0-9]+\srows","[0-9\.]+\ssecs"';
45
        $this->assertRegExp(
46
            '~catalog_product_entity_media_gallery,"ENGINE InnoDB",' . $timeRegex . '~',
47
            $commandTester->getDisplay()
48
        );
49
        $this->assertRegExp(
50
            '~catalog_product_entity_media_gallery_value,"ENGINE InnoDB",' . $timeRegex . '~',
51
            $commandTester->getDisplay()
52
        );
53
    }
54
55
    /**
56
     * @return \Symfony\Component\Console\Command\Command
57
     */
58
    protected function getCommand()
59
    {
60
        $application = $this->getApplication();
61
        $application->add(new CheckTablesCommand());
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...
62
        $command = $this->getApplication()->find('db:maintain:check-tables');
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...
63
64
        return $command;
65
    }
66
}
67