|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Util\ArrayFunctions; |
|
6
|
|
|
use Symfony\Component\Console\Input\StringInput; |
|
7
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
8
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
9
|
|
|
use N98\Magento\Command\PHPUnit\TestCase; |
|
10
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
11
|
|
|
use org\bovigo\vfs\vfsStream; |
|
12
|
|
|
|
|
13
|
|
|
class ApplicationTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @test |
|
18
|
|
|
*/ |
|
19
|
|
|
public function versionAligned() |
|
20
|
|
|
{ |
|
21
|
|
|
// constant must be same as version.txt and latest in CHANGELOG.md |
|
22
|
|
|
|
|
23
|
|
|
$projectDir = __DIR__ . '/../../..'; |
|
24
|
|
|
|
|
25
|
|
|
$versionFromVersionTxt = trim(file_get_contents($projectDir . '/version.txt')); |
|
26
|
|
|
|
|
27
|
|
|
$buffer = file_get_contents($projectDir . '/CHANGELOG.md'); |
|
28
|
|
|
|
|
29
|
|
|
$versionFromChangelog = preg_match('~^\d+\.\d+\.\d+$~m', $buffer, $matches) ? $matches[0] : null; |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals(Application::APP_VERSION, $versionFromVersionTxt, 'changes.txt same as APP_VERSION'); |
|
32
|
|
|
$this->assertEquals(Application::APP_VERSION, $versionFromChangelog, 'CHANGELOG.md same as APP_VERSION'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testExecute() |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Check autoloading |
|
39
|
|
|
*/ |
|
40
|
|
|
|
|
41
|
|
|
/* @var $application Application */ |
|
42
|
|
|
$application = require __DIR__ . '/../../../src/bootstrap.php'; |
|
43
|
|
|
$application->setMagentoRootFolder($this->getTestMagentoRoot()); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertInstanceOf('\N98\Magento\Application', $application); |
|
46
|
|
|
$loader = $application->getAutoloader(); |
|
47
|
|
|
$this->assertInstanceOf('\Composer\Autoload\ClassLoader', $loader); |
|
48
|
|
|
|
|
49
|
|
|
/* @var $loader \Composer\Autoload\ClassLoader */ |
|
50
|
|
|
$prefixes = $loader->getPrefixes(); |
|
51
|
|
|
$this->assertArrayHasKey('N98', $prefixes); |
|
52
|
|
|
|
|
53
|
|
|
$distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml')); |
|
54
|
|
|
|
|
55
|
|
|
$configArray = array( |
|
56
|
|
|
'autoloaders' => array( |
|
57
|
|
|
'N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc', |
|
58
|
|
|
), |
|
59
|
|
|
'commands' => array( |
|
60
|
|
|
'customCommands' => array( |
|
61
|
|
|
0 => 'N98MagerunTest\TestDummyCommand' |
|
62
|
|
|
), |
|
63
|
|
|
'aliases' => array( |
|
64
|
|
|
array( |
|
65
|
|
|
'ssl' => 'sys:store:list' |
|
66
|
|
|
) |
|
67
|
|
|
), |
|
68
|
|
|
), |
|
69
|
|
|
'init' => array( |
|
70
|
|
|
'options' => array( |
|
71
|
|
|
'config_model' => 'N98MagerunTest\AlternativeConfigModel', |
|
72
|
|
|
) |
|
73
|
|
|
) |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$application->setAutoExit(false); |
|
77
|
|
|
$application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray)); |
|
|
|
|
|
|
78
|
|
|
$application->run(new StringInput('list'), new NullOutput()); |
|
79
|
|
|
|
|
80
|
|
|
// Check if autoloaders, commands and aliases are registered |
|
81
|
|
|
$prefixes = $loader->getPrefixes(); |
|
82
|
|
|
$this->assertArrayHasKey('N98MagerunTest', $prefixes); |
|
83
|
|
|
|
|
84
|
|
|
$testDummyCommand = $application->find('n98mageruntest:test:dummy'); |
|
85
|
|
|
$this->assertInstanceOf('\N98MagerunTest\TestDummyCommand', $testDummyCommand); |
|
86
|
|
|
|
|
87
|
|
|
$commandTester = new CommandTester($testDummyCommand); |
|
88
|
|
|
$commandTester->execute( |
|
89
|
|
|
array( |
|
90
|
|
|
'command' => $testDummyCommand->getName(), |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
$this->assertContains('dummy', $commandTester->getDisplay()); |
|
94
|
|
|
$this->assertTrue($application->getDefinition()->hasOption('root-dir')); |
|
95
|
|
|
|
|
96
|
|
|
// check alias |
|
97
|
|
|
$this->assertInstanceOf('\N98\Magento\Command\System\Store\ListCommand', $application->find('ssl')); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testPlugins() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->getApplication(); // bootstrap implicit |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Check autoloading |
|
106
|
|
|
*/ |
|
107
|
|
|
$application = require __DIR__ . '/../../../src/bootstrap.php'; |
|
108
|
|
|
$application->setMagentoRootFolder($this->getTestMagentoRoot()); |
|
109
|
|
|
|
|
110
|
|
|
// Load plugin config |
|
111
|
|
|
$injectConfig = array( |
|
112
|
|
|
'plugin' => array( |
|
113
|
|
|
'folders' => array( |
|
114
|
|
|
__DIR__ . '/_ApplicationTestModules' |
|
115
|
|
|
) |
|
116
|
|
|
) |
|
117
|
|
|
); |
|
118
|
|
|
$application->init($injectConfig); |
|
119
|
|
|
|
|
120
|
|
|
// Check for module command |
|
121
|
|
|
$this->assertInstanceOf('TestModule\FooCommand', $application->find('testmodule:foo')); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function testComposer() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->markTestSkipped('Currently not working'); |
|
127
|
|
|
|
|
128
|
|
|
vfsStream::setup('root'); |
|
129
|
|
|
vfsStream::create( |
|
130
|
|
|
array( |
|
131
|
|
|
'htdocs' => array( |
|
132
|
|
|
'app' => array( |
|
133
|
|
|
'Mage.php' => '' |
|
134
|
|
|
) |
|
135
|
|
|
), |
|
136
|
|
|
'vendor' => array( |
|
137
|
|
|
'acme' => array( |
|
138
|
|
|
'magerun-test-module' => array( |
|
139
|
|
|
'n98-magerun2.yaml' => file_get_contents(__DIR__ . '/_ApplicationTestComposer/n98-magerun2.yaml'), |
|
|
|
|
|
|
140
|
|
|
'src' => array( |
|
141
|
|
|
'Acme' => array( |
|
142
|
|
|
'FooCommand.php' => file_get_contents(__DIR__ . '/_ApplicationTestComposer/FooCommand.php'), |
|
|
|
|
|
|
143
|
|
|
) |
|
144
|
|
|
) |
|
145
|
|
|
) |
|
146
|
|
|
), |
|
147
|
|
|
'n98' => array( |
|
148
|
|
|
'magerun' => array( |
|
149
|
|
|
'src' => array( |
|
150
|
|
|
'N98' => array( |
|
151
|
|
|
'Magento' => array( |
|
152
|
|
|
'Command' => array( |
|
153
|
|
|
'ConfigurationLoader.php' => '', |
|
154
|
|
|
), |
|
155
|
|
|
), |
|
156
|
|
|
), |
|
157
|
|
|
), |
|
158
|
|
|
), |
|
159
|
|
|
), |
|
160
|
|
|
), |
|
161
|
|
|
) |
|
162
|
|
|
); |
|
163
|
|
|
|
|
164
|
|
|
$configurationLoader = $this->getMock( |
|
165
|
|
|
'\N98\Magento\Command\ConfigurationLoader', |
|
166
|
|
|
array('getConfigurationLoaderDir'), |
|
167
|
|
|
array(array(), false, new NullOutput()) |
|
168
|
|
|
); |
|
169
|
|
|
$configurationLoader |
|
170
|
|
|
->expects($this->any()) |
|
171
|
|
|
->method('getConfigurationLoaderDir') |
|
172
|
|
|
->will($this->returnValue(vfsStream::url('root/vendor/n98/magerun/src/N98/Magento/Command'))); |
|
173
|
|
|
|
|
174
|
|
|
/* @var $application Application */ |
|
175
|
|
|
$application = require __DIR__ . '/../../../src/bootstrap.php'; |
|
176
|
|
|
$application->setMagentoRootFolder(vfsStream::url('root/htdocs')); |
|
177
|
|
|
$application->setConfigurationLoader($configurationLoader); |
|
178
|
|
|
$application->init(); |
|
179
|
|
|
|
|
180
|
|
|
// Check for module command |
|
181
|
|
|
$this->assertInstanceOf('Acme\FooCommand', $application->find('acme:foo')); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.