CheckCommandTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 16
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testCheckCommandSuccessful() 8 8 1
A testCheckCommandFailed() 8 8 1
A testCheckWithPropertyOutput() 0 16 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Abacaphiliac\DoctrineORMDiagnosticsModuleTest;
4
5
use Abacaphiliac\DoctrineORMDiagnosticsModule\CheckCommand;
6
use DoctrineModule\Component\Console\Output\PropertyOutput;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use ZendDiagnostics\Result\Failure;
11
use ZendDiagnostics\Result\Success;
12
13
/**
14
 * @covers \Abacaphiliac\DoctrineORMDiagnosticsModule\CheckCommand
15
 */
16
class CheckCommandTest extends \PHPUnit_Framework_TestCase
17
{
18
    /** @var \PHPUnit_Framework_MockObject_MockObject|Command */
19
    private $command;
20
    
21
    /** @var \PHPUnit_Framework_MockObject_MockObject|InputInterface */
22
    private $input;
23
    
24
    /** @var \PHPUnit_Framework_MockObject_MockObject|OutputInterface */
25
    private $output;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
26
    
27
    /** @var CheckCommand */
28
    private $sut;
29
30
    protected function setUp()
31
    {
32
        parent::setUp();
33
34
        $this->command = $this->getMockBuilder(Command::class)
35
            ->disableOriginalConstructor()
36
            ->getMock();
37
        
38
        $this->input = $this->getMockBuilder(InputInterface::class)->getMock();
39
40
        $this->output = $this->getMockBuilder(OutputInterface::class)->getMock();
41
        
42
        $this->sut = new CheckCommand($this->command, $this->input, $this->output);
43
    }
44
    
45 View Code Duplication
    public function testCheckCommandSuccessful()
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...
46
    {
47
        $this->command->method('run')->willReturn(0);
48
        
49
        $actual = $this->sut->check();
50
        
51
        self::assertInstanceOf(Success::class, $actual);
52
    }
53
    
54 View Code Duplication
    public function testCheckCommandFailed()
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...
55
    {
56
        $this->command->method('run')->willReturn(1);
57
        
58
        $actual = $this->sut->check();
59
        
60
        self::assertInstanceOf(Failure::class, $actual);
61
    }
62
    
63
    public function testCheckWithPropertyOutput()
64
    {
65
        /** @var \PHPUnit_Framework_MockObject_MockObject|PropertyOutput $output */
66
        $output = $this->getMockBuilder(PropertyOutput::class)->getMock();
67
        
68
        $output->method('getMessage')
69
            ->willReturn("Foo\nBar\n");
70
        
71
        $this->command->method('run')->willReturn(1);
72
        
73
        $actual = (new CheckCommand($this->command, $this->input, $output))->check();
74
        
75
        self::assertInternalType('array', $actual->getData());
76
        self::assertContains('Foo', $actual->getData());
77
        self::assertContains('Bar', $actual->getData());
78
    }
79
}
80