|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Pfilsx\FormLayer\Tests; |
|
5
|
|
|
|
|
6
|
|
|
use Pfilsx\FormLayer\Layer\EntityFormLayer; |
|
7
|
|
|
use Pfilsx\FormLayer\Maker\MakeFormLayer; |
|
8
|
|
|
use Pfilsx\FormLayer\Tests\app\Entity\Node; |
|
9
|
|
|
use Symfony\Bundle\MakerBundle\Command\MakerCommand; |
|
10
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
11
|
|
|
use Symfony\Component\Console\Input\StringInput; |
|
12
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
15
|
|
|
use Symfony\Component\Process\InputStream; |
|
16
|
|
|
|
|
17
|
|
|
class FunctionalTest extends KernelTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $app_path; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->app_path = dirname(__DIR__) . '/app'; |
|
27
|
|
|
parent::setUp(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testWiring() |
|
31
|
|
|
{ |
|
32
|
|
|
$class = MakeFormLayer::class; |
|
33
|
|
|
$commandName = $class::getCommandName(); |
|
34
|
|
|
$this->assertEquals('make:form-layer', $commandName); |
|
35
|
|
|
$command = $this->application->find($commandName); |
|
36
|
|
|
$this->assertInstanceOf(MakerCommand::class, $command); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @dataProvider getCommands |
|
41
|
|
|
* @param $name |
|
42
|
|
|
* @param $entity |
|
43
|
|
|
* @param $result |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testMaker($name, $entity, $result) |
|
46
|
|
|
{ |
|
47
|
|
|
$input = new StringInput("make:form-layer $name $entity"); |
|
48
|
|
|
$output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); |
|
49
|
|
|
$this->application->run($input, $output); |
|
50
|
|
|
$filePath = $this->app_path . "/FormLayer/$name.php"; |
|
51
|
|
|
$this->assertTrue(is_file($filePath)); |
|
52
|
|
|
$layerClass = "Pfilsx\\FormLayer\\Tests\\app\\FormLayer\\$name"; |
|
53
|
|
|
$layer = new $layerClass(); |
|
54
|
|
|
$this->assertInstanceOf(EntityFormLayer::class, $layer); |
|
55
|
|
|
$this->assertEquals($result, get_object_vars($layer)); |
|
56
|
|
|
@unlink($filePath); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getCommands() |
|
60
|
|
|
{ |
|
61
|
|
|
yield [ |
|
62
|
|
|
'FooBarTestFormLayer', |
|
63
|
|
|
null, |
|
64
|
|
|
['form_field' => null] |
|
65
|
|
|
]; |
|
66
|
|
|
yield [ |
|
67
|
|
|
'NodeTestFormLayer', |
|
68
|
|
|
'Node', |
|
69
|
|
|
[ |
|
70
|
|
|
'id' => null, |
|
71
|
|
|
'content' => null, |
|
72
|
|
|
'user' => null, |
|
73
|
|
|
'parentId' => null, |
|
74
|
|
|
'createdAt' => null, |
|
75
|
|
|
'mainNode' => null |
|
76
|
|
|
] |
|
77
|
|
|
]; |
|
78
|
|
|
yield [ |
|
79
|
|
|
'ModelTestFormLayer', |
|
80
|
|
|
'Model', |
|
81
|
|
|
[ |
|
82
|
|
|
'id' => null, |
|
83
|
|
|
'content' => null, |
|
84
|
|
|
'createdAt' => null |
|
85
|
|
|
] |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: