1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Tests\Command\Config; |
4
|
|
|
|
5
|
|
|
use SilverLeague\Console\Tests\Command\AbstractCommandTest; |
6
|
|
|
use SilverStripe\Config\Collections\ConfigCollectionInterface; |
7
|
|
|
use SilverStripe\Core\Config\Config; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @coversDefaultClass \SilverLeague\Console\Command\Config\DumpCommand |
11
|
|
|
* @package silverstripe-console |
12
|
|
|
* @author Robbie Averill <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class DumpCommandTest extends AbstractCommandTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritDoc} |
18
|
|
|
*/ |
19
|
|
|
protected function getTestCommand() |
20
|
|
|
{ |
21
|
|
|
return 'config:dump'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Ensure that the InputOptions exist |
26
|
|
|
* |
27
|
|
|
* @covers ::configure |
28
|
|
|
*/ |
29
|
|
|
public function testConfigure() |
30
|
|
|
{ |
31
|
|
|
$this->assertTrue($this->command->getDefinition()->hasOption('filter')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Test that the command can successfully be executed |
36
|
|
|
* |
37
|
|
|
* @covers ::execute |
38
|
|
|
*/ |
39
|
|
|
public function testExecute() |
40
|
|
|
{ |
41
|
|
|
$result = $this->executeTest()->getDisplay(); |
42
|
|
|
$this->assertContains('silverstripe\\control\\director', $result); |
43
|
|
|
$this->assertContains('silverstripe\\core\\injector\\injector', $result); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test that the results can be filtered |
48
|
|
|
* |
49
|
|
|
* @covers ::execute |
50
|
|
|
* @covers ::filterOutput |
51
|
|
|
*/ |
52
|
|
|
public function testExecuteWithFilteredResults() |
53
|
|
|
{ |
54
|
|
|
$result = $this->executeTest(['--filter' => 'SilverStripe\\Control\\Director'])->getDisplay(); |
55
|
|
|
$this->assertContains('silverstripe\\control\\director', $result); |
56
|
|
|
$this->assertNotContains('silverstripe\\core\\injector\\injector', $result); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Ensure that the filter is applied to any column of the data |
61
|
|
|
* |
62
|
|
|
* @covers ::filterOutput |
63
|
|
|
*/ |
64
|
|
|
public function testFilterOnAnyColumn() |
65
|
|
|
{ |
66
|
|
|
$result = $this->executeTest(['--filter' => '%$DisplayErrorHandler'])->getDisplay(); |
67
|
|
|
$this->assertContains('pushHandler', $result); |
68
|
|
|
|
69
|
|
|
$result = $this->executeTest(['--filter' => 'pushHandler'])->getDisplay(); |
70
|
|
|
$this->assertContains('%$DisplayErrorHandler', $result); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Ensure that numeric property keys are replaced with nada |
75
|
|
|
* |
76
|
|
|
* @covers ::getParsedOutput |
77
|
|
|
*/ |
78
|
|
|
public function testNumericKeysAreNotShown() |
79
|
|
|
{ |
80
|
|
|
Config::modify()->set('FooBar', 'my_property', [1 => 'baz', 'bar' => 'banter']); |
81
|
|
|
$result = $this->executeTest(['--filter' => 'FooBar'])->getDisplay(); |
82
|
|
|
$this->assertNotContains('1', $result); |
83
|
|
|
$this->assertContains('bar', $result); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Ensure that nested array values for properties are displayed as JSON. Since it crosses multiple lines, |
88
|
|
|
* we can't assert it exactly. |
89
|
|
|
* |
90
|
|
|
* @covers ::getParsedOutput |
91
|
|
|
*/ |
92
|
|
|
public function testNestedArrayValuesAreDisplayedAsJson() |
93
|
|
|
{ |
94
|
|
|
$input = ['brands' => ['good' => 'Heatings R Us', 'great' => 'Never-B-Cold', 'best' => 'Luv-Fyre']]; |
95
|
|
|
Config::modify()->set('HeatingSupplies', 'brands', $input); |
96
|
|
|
$result = $this->executeTest()->getDisplay(); |
97
|
|
|
$this->assertContains('"great": "Never-B-Cold",', $result); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Ensure that a ConfigCollectionInterface is returned |
102
|
|
|
* |
103
|
|
|
* @covers \SilverLeague\Console\Command\Config\AbstractConfigCommand::getConfig |
104
|
|
|
*/ |
105
|
|
|
public function testGetConfigCollectionInterface() |
106
|
|
|
{ |
107
|
|
|
$result = $this->command->getConfig(); |
108
|
|
|
$this->assertInstanceOf(ConfigCollectionInterface::class, $result); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|