Skip to content

Commit 86ffa6c

Browse files
author
Stanislav Idolov
authored
ENGCOM-841: Add quoting for base path in DI compile command #13789
2 parents e1c39e5 + 6d618b0 commit 86ffa6c

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

setup/src/Magento/Setup/Console/Command/DiCompileCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private function getExcludedModulePaths(array $modulePaths)
239239
$vendorPathsRegExps[] = $vendorDir
240240
. '/(?:' . join('|', $vendorModules) . ')';
241241
}
242-
$basePathsRegExps[] = $basePath
242+
$basePathsRegExps[] = preg_quote($basePath, '#')
243243
. '/(?:' . join('|', $vendorPathsRegExps) . ')';
244244
}
245245

@@ -258,6 +258,10 @@ private function getExcludedModulePaths(array $modulePaths)
258258
*/
259259
private function getExcludedLibraryPaths(array $libraryPaths)
260260
{
261+
$libraryPaths = array_map(function ($libraryPath) {
262+
return preg_quote($libraryPath, '#');
263+
}, $libraryPaths);
264+
261265
$excludedLibraryPaths = [
262266
'#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?Test#',
263267
'#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?tests#',
@@ -274,7 +278,7 @@ private function getExcludedLibraryPaths(array $libraryPaths)
274278
private function getExcludedSetupPaths($setupPath)
275279
{
276280
return [
277-
'#^(?:' . $setupPath . ')(/[\\w]+)*/Test#'
281+
'#^(?:' . preg_quote($setupPath, '#') . ')(/[\\w]+)*/Test#'
278282
];
279283
}
280284

setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Component\ComponentRegistrar;
99
use Magento\Setup\Console\Command\DiCompileCommand;
10+
use Magento\Setup\Module\Di\App\Task\OperationFactory;
1011
use Symfony\Component\Console\Tester\CommandTester;
1112

1213
/**
@@ -61,6 +62,10 @@ public function setUp()
6162
$this->managerMock = $this->createMock(\Magento\Setup\Module\Di\App\Task\Manager::class);
6263
$this->directoryListMock =
6364
$this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class);
65+
$this->directoryListMock->expects($this->any())->method('getPath')->willReturnMap([
66+
[\Magento\Framework\App\Filesystem\DirectoryList::SETUP, '/path (1)/to/setup/'],
67+
]);
68+
6469
$this->filesystemMock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
6570
->disableOriginalConstructor()
6671
->getMock();
@@ -70,8 +75,8 @@ public function setUp()
7075
->getMock();
7176
$this->componentRegistrarMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class);
7277
$this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([
73-
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']],
74-
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']],
78+
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path (1)/to/module/two']],
79+
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path (1)/to/library/two']],
7580
]);
7681

7782
$this->command = new DiCompileCommand(
@@ -128,7 +133,28 @@ public function testExecute()
128133
->method('create')
129134
->with(\Symfony\Component\Console\Helper\ProgressBar::class)
130135
->willReturn($progressBar);
131-
$this->managerMock->expects($this->exactly(7))->method('addOperation');
136+
137+
$this->managerMock->expects($this->exactly(7))->method('addOperation')
138+
->withConsecutive(
139+
[OperationFactory::PROXY_GENERATOR, []],
140+
[OperationFactory::REPOSITORY_GENERATOR, $this->anything()],
141+
[OperationFactory::DATA_ATTRIBUTES_GENERATOR, []],
142+
[OperationFactory::APPLICATION_CODE_GENERATOR, $this->callback(function ($subject) {
143+
$this->assertEmpty(array_diff($subject['excludePatterns'], [
144+
"#^(?:/path \(1\)/to/setup/)(/[\w]+)*/Test#",
145+
"#^(?:/path/to/library/one|/path \(1\)/to/library/two)/([\w]+/)?Test#",
146+
"#^(?:/path/to/library/one|/path \(1\)/to/library/two)/([\w]+/)?tests#",
147+
"#^(?:/path/to/(?:module/(?:one))|/path \(1\)/to/(?:module/(?:two)))/Test#",
148+
"#^(?:/path/to/(?:module/(?:one))|/path \(1\)/to/(?:module/(?:two)))/tests#"
149+
]));
150+
return true;
151+
})],
152+
[OperationFactory::INTERCEPTION, $this->anything()],
153+
[OperationFactory::AREA_CONFIG_GENERATOR, $this->anything()],
154+
[OperationFactory::INTERCEPTION_CACHE, $this->anything()]
155+
)
156+
;
157+
132158
$this->managerMock->expects($this->once())->method('process');
133159
$tester = new CommandTester($this->command);
134160
$tester->execute([]);

0 commit comments

Comments
 (0)