-
-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathMakeCommandTest.php
More file actions
101 lines (84 loc) · 3.26 KB
/
MakeCommandTest.php
File metadata and controls
101 lines (84 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\MakerBundle\Tests\Maker;
use Symfony\Bundle\MakerBundle\Maker\MakeCommand;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;
use Symfony\Component\Yaml\Yaml;
class MakeCommandTest extends MakerTestCase
{
protected function getMakerClass(): string
{
return MakeCommand::class;
}
public function getTestDetails(): \Generator
{
yield 'it_makes_an_invokable_command_no_attributes' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$runner->runMaker([
// command name
'app:foo',
// create invokable command by default
'',
]);
$this->runCommandTest($runner, 'it_makes_a_command.php');
}),
];
yield 'it_makes_an_old_structured_command_no_attributes' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$runner->runMaker([
// command name
'app:foo',
// create a command with the old structure by default
'yes',
]);
$this->runCommandTest($runner, 'it_makes_a_command.php');
}),
];
yield 'it_makes_a_command_with_attributes' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$runner->runMaker([
// command name
'app:foo',
// create invokable command by default
'',
]);
$this->runCommandTest($runner, 'it_makes_a_command.php');
$commandFileContents = file_get_contents($runner->getPath('src/Command/FooCommand.php'));
self::assertStringContainsString('use Symfony\Component\Console\Attribute\AsCommand;', $commandFileContents);
self::assertStringContainsString('#[AsCommand(', $commandFileContents);
}),
];
yield 'it_makes_a_command_in_custom_namespace' => [$this->createMakerTest()
->changeRootNamespace('Custom')
->run(function (MakerTestRunner $runner) {
$runner->writeFile(
'config/packages/dev/maker.yaml',
Yaml::dump(['maker' => ['root_namespace' => 'Custom']])
);
$runner->runMaker([
// command name
'app:foo',
// create invokable command by default
'',
]);
$this->runCommandTest($runner, 'it_makes_a_command_in_custom_namespace.php');
}),
];
}
private function runCommandTest(MakerTestRunner $runner, string $filename): void
{
$runner->copy(
'make-command/tests/'.$filename,
'tests/GeneratedCommandTest.php'
);
$runner->runTests();
}
}