|
1
|
|
|
<?php |
|
2
|
|
|
namespace Acelaya\Test\Doctrine\Console; |
|
3
|
|
|
|
|
4
|
|
|
use Acelaya\Doctrine\Console\DumpTypeClassesCommand; |
|
5
|
|
|
use Acelaya\Doctrine\Exception\InvalidArgumentException; |
|
6
|
|
|
use Acelaya\Doctrine\Registrator\EnumTypeRegistrator; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Prophecy\Prophecy\MethodProphecy; |
|
9
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
10
|
|
|
use Symfony\Component\Console\Application; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
13
|
|
|
|
|
14
|
|
|
class DumpTypeClassesCommandTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var DumpTypeClassesCommand |
|
18
|
|
|
*/ |
|
19
|
|
|
private $command; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var CommandTester |
|
22
|
|
|
*/ |
|
23
|
|
|
private $commandTester; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ObjectProphecy |
|
26
|
|
|
*/ |
|
27
|
|
|
private $registrator; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->registrator = $this->prophesize(EnumTypeRegistrator::class); |
|
32
|
|
|
$this->command = new DumpTypeClassesCommand($this->registrator->reveal(), []); |
|
33
|
|
|
|
|
34
|
|
|
$app = new Application(); |
|
35
|
|
|
$app->add($this->command); |
|
36
|
|
|
$this->commandTester = new CommandTester($this->command); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @test |
|
41
|
|
|
*/ |
|
42
|
|
|
public function correctExecutionPrintsSuccess() |
|
43
|
|
|
{ |
|
44
|
|
|
/** @var MethodProphecy $registerTypes */ |
|
45
|
|
|
$registerTypes = $this->registrator->registerEnumTypes([])->willReturn(null); |
|
46
|
|
|
|
|
47
|
|
|
$this->commandTester->execute([]); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertContains('Success!', $this->commandTester->getDisplay()); |
|
50
|
|
|
$registerTypes->shouldHaveBeenCalled(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @test |
|
55
|
|
|
*/ |
|
56
|
|
View Code Duplication |
public function exceptionPrintsError() |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
/** @var MethodProphecy $registerTypes */ |
|
59
|
|
|
$registerTypes = $this->registrator->registerEnumTypes([])->willThrow(InvalidArgumentException::class); |
|
60
|
|
|
|
|
61
|
|
|
$this->commandTester->execute([]); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertContains('Error!', $this->commandTester->getDisplay()); |
|
64
|
|
|
$registerTypes->shouldHaveBeenCalled(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @test |
|
69
|
|
|
*/ |
|
70
|
|
View Code Duplication |
public function exceptionIsPrintedInVerboseMode() |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
/** @var MethodProphecy $registerTypes */ |
|
73
|
|
|
$registerTypes = $this->registrator->registerEnumTypes([])->willThrow(new InvalidArgumentException( |
|
74
|
|
|
'The exception message' |
|
75
|
|
|
)); |
|
76
|
|
|
|
|
77
|
|
|
$this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertContains('The exception message', $this->commandTester->getDisplay()); |
|
80
|
|
|
$registerTypes->shouldHaveBeenCalled(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
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.