|
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); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testExecuteShouldCreateTestAndCommunicateCorrectMessage() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->application->add($this->sut); |
|
38
|
|
|
|
|
39
|
|
|
$this->testGeneratorMock |
|
40
|
|
|
->shouldReceive('generate') |
|
|
|
|
|
|
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
|
|
|
|