TopCommandTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testReturnNonZeroExistCode() 0 48 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Petrica
5
 * Date: 5/29/2016
6
 * Time: 0:11
7
 */
8
namespace Petrica\StatsdSystem\Tests\Model;
9
10
use Petrica\StatsdSystem\Model\TopCommand;
11
12
class TopCommandTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testReturnNonZeroExistCode()
15
    {
16
        /** @var TopCommand $topCommand */
17
        $topCommand = $this->getMockBuilder('Petrica\StatsdSystem\Model\TopCommand')
18
            ->disableOriginalConstructor()
19
            ->setMethods(array(
20
                'getCommand'
21
            ))
22
            ->getMock();
23
24
        $command = $this->getMockBuilder('Tivie\Command')
25
            ->disableOriginalConstructor()
26
            ->setMethods(array(
27
                'run'
28
            ))
29
            ->getMock();
30
31
        $result = $this->getMockBuilder('Tivie\Command\Result')
32
            ->disableOriginalConstructor()
33
            ->setMethods(array(
34
                'getExitCode',
35
                'getStdErr'
36
            ))
37
            ->getMock();
38
39
        /**
40
         * Simulate command not found
41
         */
42
        $result->method('getExitCode')
43
            ->willReturn(1);
44
        $result->method('getStdErr')
45
            ->willReturn('Does not exist.');
46
47
        $command->expects($this->once())
48
            ->method('run')
49
            ->willReturn($result);
50
51
        $topCommand->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Petrica\StatsdSystem\Model\TopCommand>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
            ->method('getCommand')
53
            ->willReturn($command);
54
55
        $this->setExpectedException(
56
            '\RuntimeException',
57
            'Command failed. Exit code 1, output Does not exist.'
58
        );
59
60
        $topCommand->run();
61
    }
62
}