|
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\GetActionCommand; |
|
8
|
|
|
use SlayerBirden\DFCodeGeneration\Writer\WriteInterface; |
|
9
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
10
|
|
|
|
|
11
|
|
|
final class GetActionCommandTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testExecuteDryRun() |
|
14
|
|
|
{ |
|
15
|
|
|
$writer = $this->prophesize(WriteInterface::class); |
|
16
|
|
|
$tester = new CommandTester(new GetActionCommand(null, $writer->reveal())); |
|
17
|
|
|
$tester->execute([ |
|
18
|
|
|
'entity' => Hubby::class, |
|
19
|
|
|
]); |
|
20
|
|
|
|
|
21
|
|
|
$display = $tester->getDisplay(); |
|
22
|
|
|
|
|
23
|
|
|
# controller |
|
24
|
|
|
$this->assertContains('GetHubbyAction', $display); |
|
25
|
|
|
# config |
|
26
|
|
|
$this->assertContains('ConfigProvider', $display); |
|
27
|
|
|
# factories |
|
28
|
|
|
$this->assertContains('HubbyHydratorFactory', $display); |
|
29
|
|
|
$this->assertContains('HubbyResourceMiddlewareFactory', $display); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testExecuteForce() |
|
33
|
|
|
{ |
|
34
|
|
|
$writer = new class implements WriteInterface { |
|
|
|
|
|
|
35
|
|
|
public $content = ''; |
|
36
|
|
|
|
|
37
|
|
|
public function write(string $content, string $fileName): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->content .= $content; |
|
40
|
|
|
} |
|
41
|
|
|
}; |
|
42
|
|
|
$tester = new CommandTester(new GetActionCommand(null, $writer)); |
|
43
|
|
|
$tester->execute([ |
|
44
|
|
|
'entity' => Hubby::class, |
|
45
|
|
|
'--force' => true, |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
$content = $writer->content; |
|
49
|
|
|
|
|
50
|
|
|
$this->assertContains('GetHubbyAction', $content); |
|
51
|
|
|
# config |
|
52
|
|
|
$this->assertContains('ConfigProvider', $content); |
|
53
|
|
|
# factories |
|
54
|
|
|
$this->assertContains('HubbyHydratorFactory', $content); |
|
55
|
|
|
$this->assertContains('HubbyResourceMiddlewareFactory', $content); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
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.