Passed
Push — master ( 9dadbc...3d8989 )
by Kamil
02:26
created

testExecuteShouldCreateTestAndCommunicateCorrectMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace UniGen\Bundle\UniGenBundle\Tests\Command;
4
5
use Mockery;
6
use Mockery\MockInterface;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Console\Application;
9
use Symfony\Component\Console\Tester\CommandTester;
10
use UniGen\Bundle\UniGenBundle\Command\TestGeneratorCommand;
11
use UniGen\TestGenerator;
12
13
class GeneratorCommandTest extends TestCase
14
{
15
    /** @var Application */
16
    private $application;
17
18
    /** @var TestGenerator|MockInterface */
19
    private $testGeneratorMock;
20
21
    /** @var TestGeneratorCommand */
22
    private $sut;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function setUp()
28
    {
29
        $this->application = new Application();
30
        $this->testGeneratorMock = Mockery::mock(TestGenerator::class);
31
32
        $this->sut = new TestGeneratorCommand($this->testGeneratorMock);
0 ignored issues
show
Bug introduced by
$this->testGeneratorMock of type Mockery\MockInterface is incompatible with the type UniGen\TestGenerator expected by parameter $testGenerator of UniGen\Bundle\UniGenBund...rCommand::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $this->sut = new TestGeneratorCommand(/** @scrutinizer ignore-type */ $this->testGeneratorMock);
Loading history...
33
    }
34
35
    public function testExecuteShouldCreateTestAndCommunicateCorrectMessage()
36
    {
37
        $this->application->add($this->sut);
38
39
        $this->testGeneratorMock
40
            ->shouldReceive('generate')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on UniGen\TestGenerator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            ->/** @scrutinizer ignore-call */ 
41
              shouldReceive('generate')

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...
41
            ->with('dir/sutPath.php');
42
43
        $commandTester = new CommandTester($this->application->find('unigen:generate'));
44
45
        $result = $commandTester->execute(['sut_path' => 'dir/sutPath.php']);
46
47
        $this->assertEquals(0, $result);
48
        $this->assertEquals(
49
            'Test file dir/sutPath.php has been generated successfully',
50
            $commandTester->getDisplay()
51
        );
52
    }
53
54
    public function testExecuteShouldShowErrorMessageWhenFail()
55
    {
56
        $this->application->add($this->sut);
57
58
        $this->testGeneratorMock
59
            ->shouldReceive('generate')
60
            ->with('dir/sutPath.php')
61
            ->andThrow(\InvalidArgumentException::class, 'error-message');
62
63
        $commandTester = new CommandTester($this->application->find('unigen:generate'));
64
65
        $result = $commandTester->execute(['sut_path' => 'dir/sutPath.php']);
66
67
        $this->assertEquals(1, $result);
68
        $this->assertEquals('error-message', $commandTester->getDisplay());
69
    }
70
}
71