-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathConfigDumpReferenceCommandTest.php
167 lines (142 loc) · 5.86 KB
/
ConfigDumpReferenceCommandTest.php
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Command\ConfigDumpReferenceCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @group functional
*/
class ConfigDumpReferenceCommandTest extends AbstractWebTestCase
{
/**
* @testWith [true]
* [false]
*/
public function testShowList(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute([]);
$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('Available registered bundles with their extension alias if available', $tester->getDisplay());
$this->assertStringContainsString(' DefaultConfigTestBundle default_config_test', $tester->getDisplay());
$this->assertStringContainsString(' ExtensionWithoutConfigTestBundle extension_without_config_test', $tester->getDisplay());
$this->assertStringContainsString(' FrameworkBundle framework', $tester->getDisplay());
$this->assertStringContainsString(' TestBundle test', $tester->getDisplay());
$this->assertStringContainsString('Available registered non-bundle extension aliases', $tester->getDisplay());
$this->assertStringContainsString(' foo', $tester->getDisplay());
$this->assertStringContainsString(' test_dump', $tester->getDisplay());
}
/**
* @testWith [true]
* [false]
*/
public function testDumpKernelExtension(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute(['name' => 'foo']);
$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('foo:', $tester->getDisplay());
$this->assertStringContainsString(' bar', $tester->getDisplay());
}
/**
* @testWith [true]
* [false]
*/
public function testDumpBundleName(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute(['name' => 'TestBundle']);
$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('test:', $tester->getDisplay());
$this->assertStringContainsString(' custom:', $tester->getDisplay());
}
/**
* @testWith [true]
* [false]
*/
public function testDumpExtensionConfigWithoutBundle(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute(['name' => 'test_dump']);
$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
}
/**
* @testWith [true]
* [false]
*/
public function testDumpAtPath(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute([
'name' => 'test',
'path' => 'array',
]);
$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertSame(<<<'EOL'
# Default configuration for extension with alias: "test" at path "array"
array:
child1: ~
child2: ~
EOL
, $tester->getDisplay(true));
}
/**
* @testWith [true]
* [false]
*/
public function testDumpAtPathXml(bool $debug)
{
$tester = $this->createCommandTester($debug);
$ret = $tester->execute([
'name' => 'test',
'path' => 'array',
'--format' => 'xml',
]);
$this->assertSame(1, $ret);
$this->assertStringContainsString('[ERROR] The "path" option is only available for the "yaml" format.', $tester->getDisplay());
}
/**
* @dataProvider provideCompletionSuggestions
*/
public function testComplete(bool $debug, array $input, array $expectedSuggestions)
{
$application = $this->createApplication($debug);
$application->add(new ConfigDumpReferenceCommand());
$tester = new CommandCompletionTester($application->get('config:dump-reference'));
$suggestions = $tester->complete($input);
$this->assertSame($expectedSuggestions, $suggestions);
}
public static function provideCompletionSuggestions(): iterable
{
$name = ['foo', 'default_config_test', 'extension_without_config_test', 'framework', 'test', 'test_dump', 'DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
yield 'name, no debug' => [false, [''], $name];
yield 'name, debug' => [true, [''], $name];
$optionFormat = ['yaml', 'xml'];
yield 'option --format, no debug' => [false, ['--format', ''], $optionFormat];
yield 'option --format, debug' => [true, ['--format', ''], $optionFormat];
}
private function createCommandTester(bool $debug): CommandTester
{
$command = $this->createApplication($debug)->find('config:dump-reference');
return new CommandTester($command);
}
private function createApplication(bool $debug): Application
{
$kernel = static::createKernel(['debug' => $debug, 'test_case' => 'ConfigDump', 'root_config' => 'config.yml']);
$application = new Application($kernel);
$application->doRun(new ArrayInput([]), new NullOutput());
return $application;
}
}