Skip to content

Commit 582a673

Browse files
🔃 [EngCom] Public Pull Requests - 2.1-develop
Accepted Public Pull Requests: - #13806: [Backport 2.1] Add quoting for base path in DI compile command (by @simpleadm)
2 parents 6fd3077 + ef45203 commit 582a673

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function getExcludedModulePaths(array $modulePaths)
221221
$vendorPathsRegExps[] = $vendorDir
222222
. '/(?:' . join('|', $vendorModules) . ')';
223223
}
224-
$basePathsRegExps[] = $basePath
224+
$basePathsRegExps[] = preg_quote($basePath, '#')
225225
. '/(?:' . join('|', $vendorPathsRegExps) . ')';
226226
}
227227

@@ -240,6 +240,10 @@ private function getExcludedModulePaths(array $modulePaths)
240240
*/
241241
private function getExcludedLibraryPaths(array $libraryPaths)
242242
{
243+
$libraryPaths = array_map(function ($libraryPath) {
244+
return preg_quote($libraryPath, '#');
245+
}, $libraryPaths);
246+
243247
$excludedLibraryPaths = [
244248
'#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?Test#',
245249
'#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?tests#',

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

Lines changed: 28 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
class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
@@ -63,6 +64,9 @@ public function setUp()
6364
->willReturn($this->objectManagerMock);
6465
$this->managerMock = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
6566
$this->directoryListMock = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
67+
$this->directoryListMock->expects($this->any())->method('getPath')->willReturnMap([
68+
[\Magento\Framework\App\Filesystem\DirectoryList::SETUP, '/path (1)/to/setup/'],
69+
]);
6670
$this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
6771
->disableOriginalConstructor()
6872
->getMock();
@@ -78,8 +82,8 @@ public function setUp()
7882
false
7983
);
8084
$this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([
81-
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']],
82-
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']],
85+
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path (1)/to/module/two']],
86+
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path (1)/to/library/two']],
8387
]);
8488

8589
$this->command = new DiCompileCommand(
@@ -136,7 +140,28 @@ public function testExecute()
136140
->method('create')
137141
->with('Symfony\Component\Console\Helper\ProgressBar')
138142
->willReturn($progressBar);
139-
$this->managerMock->expects($this->exactly(7))->method('addOperation');
143+
144+
$this->managerMock->expects($this->exactly(7))->method('addOperation')
145+
->withConsecutive(
146+
[OperationFactory::PROXY_GENERATOR, []],
147+
[OperationFactory::REPOSITORY_GENERATOR, $this->anything()],
148+
[OperationFactory::DATA_ATTRIBUTES_GENERATOR, []],
149+
[OperationFactory::APPLICATION_CODE_GENERATOR, $this->callback(function ($subject) {
150+
$this->assertEmpty(array_diff($subject['excludePatterns'], [
151+
"#^(?:/path \(1\)/to/setup/)(/[\w]+)*/Test#",
152+
"#^(?:/path/to/library/one|/path \(1\)/to/library/two)/([\w]+/)?Test#",
153+
"#^(?:/path/to/library/one|/path \(1\)/to/library/two)/([\w]+/)?tests#",
154+
"#^(?:/path/to/(?:module/(?:one))|/path \(1\)/to/(?:module/(?:two)))/Test#",
155+
"#^(?:/path/to/(?:module/(?:one))|/path \(1\)/to/(?:module/(?:two)))/tests#"
156+
]));
157+
return true;
158+
})],
159+
[OperationFactory::INTERCEPTION, $this->anything()],
160+
[OperationFactory::AREA_CONFIG_GENERATOR, $this->anything()],
161+
[OperationFactory::INTERCEPTION_CACHE, $this->anything()]
162+
)
163+
;
164+
140165
$this->managerMock->expects($this->once())->method('process');
141166
$tester = new CommandTester($this->command);
142167
$tester->execute([]);

0 commit comments

Comments
 (0)