1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Command; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SlayerBirden\DFCodeGeneration\Command\Controllers\AddActionCommand; |
8
|
|
|
use SlayerBirden\DFCodeGeneration\Util\CodeLoader; |
9
|
|
|
use SlayerBirden\DFCodeGeneration\Writer\WriteInterface; |
10
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
11
|
|
|
|
12
|
|
|
class AddActionCommandTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public static function setUpBeforeClass() |
15
|
|
|
{ |
16
|
|
|
$hubbyBody = <<<'HUBBY' |
17
|
|
|
<?php |
18
|
|
|
use Doctrine\ORM\Mapping as ORM; |
19
|
|
|
/** |
20
|
|
|
* @ORM\Entity @ORM\Table(name="hubbies") |
21
|
|
|
*/ |
22
|
|
|
class Hubby |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @ORM\Id |
26
|
|
|
* @ORM\Column(type="string") |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $hubbyId; |
30
|
|
|
/** |
31
|
|
|
* @ORM\Column(type="string", nullable=true) |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $name; |
35
|
|
|
} |
36
|
|
|
HUBBY; |
37
|
|
|
CodeLoader::loadCode($hubbyBody, 'hubbyEntity.php'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testExecuteDryRun() |
41
|
|
|
{ |
42
|
|
|
$writer = $this->prophesize(WriteInterface::class); |
43
|
|
|
$tester = new CommandTester(new AddActionCommand(null, $writer->reveal())); |
44
|
|
|
$tester->execute([ |
45
|
|
|
'entity' => 'Hubby', |
46
|
|
|
]); |
47
|
|
|
|
48
|
|
|
$display = $tester->getDisplay(); |
49
|
|
|
|
50
|
|
|
# controller |
51
|
|
|
$this->assertContains('AddHubbyAction', $display); |
52
|
|
|
# config |
53
|
|
|
$this->assertContains('ConfigProvider', $display); |
54
|
|
|
# factories |
55
|
|
|
$this->assertContains('HubbyHydratorFactory', $display); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testExecuteForce() |
59
|
|
|
{ |
60
|
|
|
$writer = new class implements WriteInterface { |
|
|
|
|
61
|
|
|
public $content = ''; |
62
|
|
|
|
63
|
|
|
public function write(string $content, string $fileName): void |
64
|
|
|
{ |
65
|
|
|
$this->content .= $content; |
66
|
|
|
} |
67
|
|
|
}; |
68
|
|
|
$tester = new CommandTester(new AddActionCommand(null, $writer)); |
69
|
|
|
$tester->execute([ |
70
|
|
|
'entity' => 'Hubby', |
71
|
|
|
'--force' => true, |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
$content = $writer->content; |
75
|
|
|
|
76
|
|
|
$this->assertContains('AddHubbyAction', $content); |
77
|
|
|
# config |
78
|
|
|
$this->assertContains('ConfigProvider', $content); |
79
|
|
|
# factories |
80
|
|
|
$this->assertContains('HubbyHydratorFactory', $content); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.