|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* @author Tom Klingenberg <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace N98\Magento\Application; |
|
7
|
|
|
|
|
8
|
|
|
use Composer\Autoload\ClassLoader; |
|
9
|
|
|
use ErrorException; |
|
10
|
|
|
use N98\Magento\Application; |
|
11
|
|
|
use N98\Magento\Command\PHPUnit\TestCase; |
|
12
|
|
|
use Symfony\Component\Console\Command\Command; |
|
13
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
16
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
|
17
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class ConfigTest |
|
21
|
|
|
* |
|
22
|
|
|
* @covers N98\Magento\Application\Config |
|
23
|
|
|
* @package N98\Magento\Application |
|
24
|
|
|
*/ |
|
25
|
|
|
class ConfigTest extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @test |
|
29
|
|
|
*/ |
|
30
|
|
|
public function creation() |
|
31
|
|
|
{ |
|
32
|
|
|
$config = new Config(); |
|
33
|
|
|
$this->assertInstanceOf(__NAMESPACE__ . '\\Config', $config); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @test |
|
38
|
|
|
*/ |
|
39
|
|
|
public function loader() |
|
40
|
|
|
{ |
|
41
|
|
|
$config = new Config(); |
|
42
|
|
|
|
|
43
|
|
|
try { |
|
44
|
|
|
$config->load(); |
|
45
|
|
|
$this->fail('An expected exception was not thrown'); |
|
46
|
|
|
} catch (ErrorException $e) { |
|
47
|
|
|
$this->assertEquals('Configuration not yet fully loaded', $e->getMessage()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->assertEquals(array(), $config->getConfig()); |
|
51
|
|
|
|
|
52
|
|
|
$loader = $config->getLoader(); |
|
53
|
|
|
$this->assertInstanceOf(__NAMESPACE__ . '\\ConfigurationLoader', $loader); |
|
54
|
|
|
$this->assertSame($loader, $config->getLoader()); |
|
55
|
|
|
|
|
56
|
|
|
$loader->loadStageTwo(""); |
|
57
|
|
|
$config->load(); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertInternalType('array', $config->getConfig()); |
|
60
|
|
|
$this->assertGreaterThan(4, count($config->getConfig())); |
|
61
|
|
|
|
|
62
|
|
|
$config->setConfigurationLoader($loader); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* config array setter is used in some tests on @see \N98\Magento\Application::setConfig() |
|
67
|
|
|
* |
|
68
|
|
|
* @test |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setConfig() |
|
71
|
|
|
{ |
|
72
|
|
|
$config = new Config(); |
|
73
|
|
|
$config->setConfig(array(0, 1, 2)); |
|
74
|
|
|
$this->assertSame($config->getConfig()[1], 1); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @test |
|
79
|
|
|
*/ |
|
80
|
|
|
public function configCommandAlias() |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
$config = new Config(); |
|
83
|
|
|
$input = new ArgvInput(); |
|
84
|
|
|
$actual = $config->checkConfigCommandAlias($input); |
|
85
|
|
|
$this->assertInstanceOf('Symfony\Component\Console\Input\InputInterface', $actual); |
|
86
|
|
|
|
|
87
|
|
|
$saved = $_SERVER['argv']; |
|
88
|
|
|
{ |
|
89
|
|
|
$config->setConfig(array('commands' => array('aliases' => array(array('list-help' => 'list --help'))))); |
|
90
|
|
|
$definition = new InputDefinition(); |
|
91
|
|
|
$definition->addArgument(new InputArgument('command')); |
|
92
|
|
|
|
|
93
|
|
|
$argv = array('/path/to/command', 'list-help'); |
|
94
|
|
|
$_SERVER['argv'] = $argv; |
|
95
|
|
|
$input = new ArgvInput($argv, $definition); |
|
96
|
|
|
$this->assertSame('list-help', (string) $input); |
|
97
|
|
|
$actual = $config->checkConfigCommandAlias($input); |
|
98
|
|
|
$this->assertSame('list-help', $actual->getFirstArgument()); |
|
99
|
|
|
$this->assertSame('list-help --help', (string) $actual); |
|
100
|
|
|
} |
|
101
|
|
|
$_SERVER['argv'] = $saved; |
|
102
|
|
|
|
|
103
|
|
|
$command = new Command('list'); |
|
104
|
|
|
|
|
105
|
|
|
$config->registerConfigCommandAlias($command); |
|
106
|
|
|
|
|
107
|
|
|
$this->assertSame(array('list-help'), $command->getAliases()); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @test |
|
112
|
|
|
*/ |
|
113
|
|
View Code Duplication |
public function customCommands() |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
$array = array( |
|
116
|
|
|
'commands' => array( |
|
117
|
|
|
'customCommands' => array( |
|
118
|
|
|
'N98\Magento\Command\Config\GetCommand', |
|
119
|
|
|
array('name' => 'N98\Magento\Command\Config\GetCommand'), |
|
120
|
|
|
) |
|
121
|
|
|
) |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
$output = new BufferedOutput(); |
|
125
|
|
|
$output->setVerbosity($output::VERBOSITY_DEBUG); |
|
126
|
|
|
|
|
127
|
|
|
$config = new Config(array(), false, $output); |
|
128
|
|
|
$config->setConfig($array); |
|
129
|
|
|
|
|
130
|
|
|
/** @var Application $application */ |
|
131
|
|
|
$application = $this->getMock('N98\Magento\Application'); |
|
132
|
|
|
$config->registerCustomCommands($application); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @test |
|
137
|
|
|
*/ |
|
138
|
|
View Code Duplication |
public function registerCustomAutoloaders() |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
$array = array( |
|
141
|
|
|
'autoloaders' => array('$prefix' => '$path'), |
|
142
|
|
|
'autoloaders_psr4' => array('$prefix\\' => '$path'), |
|
143
|
|
|
); |
|
144
|
|
|
|
|
145
|
|
|
$output = new BufferedOutput(); |
|
146
|
|
|
|
|
147
|
|
|
$config = new Config(array(), false, $output); |
|
148
|
|
|
$config->setConfig($array); |
|
149
|
|
|
|
|
150
|
|
|
$autloader = new ClassLoader(); |
|
151
|
|
|
$config->registerCustomAutoloaders($autloader); |
|
152
|
|
|
|
|
153
|
|
|
$output->setVerbosity($output::VERBOSITY_DEBUG); |
|
154
|
|
|
$config->registerCustomAutoloaders($autloader); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @test |
|
159
|
|
|
*/ |
|
160
|
|
|
public function loadPartialConfig() |
|
161
|
|
|
{ |
|
162
|
|
|
$config = new Config(); |
|
163
|
|
|
$this->assertEquals(array(), $config->getDetectSubFolders()); |
|
164
|
|
|
$config->loadPartialConfig(false); |
|
165
|
|
|
$actual = $config->getDetectSubFolders(); |
|
166
|
|
|
$this->assertInternalType('array', $actual); |
|
167
|
|
|
$this->assertNotEquals(array(), $actual); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: