diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php index 904840869fdeb..f918eef9d5d55 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php @@ -239,7 +239,7 @@ private function getExcludedModulePaths(array $modulePaths) $vendorPathsRegExps[] = $vendorDir . '/(?:' . join('|', $vendorModules) . ')'; } - $basePathsRegExps[] = $basePath + $basePathsRegExps[] = preg_quote($basePath, '#') . '/(?:' . join('|', $vendorPathsRegExps) . ')'; } @@ -258,6 +258,10 @@ private function getExcludedModulePaths(array $modulePaths) */ private function getExcludedLibraryPaths(array $libraryPaths) { + $libraryPaths = array_map(function ($libraryPath) { + return preg_quote($libraryPath, '#'); + }, $libraryPaths); + $excludedLibraryPaths = [ '#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?Test#', '#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?tests#', @@ -274,7 +278,7 @@ private function getExcludedLibraryPaths(array $libraryPaths) private function getExcludedSetupPaths($setupPath) { return [ - '#^(?:' . $setupPath . ')(/[\\w]+)*/Test#' + '#^(?:' . preg_quote($setupPath, '#') . ')(/[\\w]+)*/Test#' ]; } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php index 388aa0670e069..20bbb5902d4d2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php @@ -7,6 +7,7 @@ use Magento\Framework\Component\ComponentRegistrar; use Magento\Setup\Console\Command\DiCompileCommand; +use Magento\Setup\Module\Di\App\Task\OperationFactory; use Symfony\Component\Console\Tester\CommandTester; /** @@ -61,6 +62,10 @@ public function setUp() $this->managerMock = $this->createMock(\Magento\Setup\Module\Di\App\Task\Manager::class); $this->directoryListMock = $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class); + $this->directoryListMock->expects($this->any())->method('getPath')->willReturnMap([ + [\Magento\Framework\App\Filesystem\DirectoryList::SETUP, '/path (1)/to/setup/'], + ]); + $this->filesystemMock = $this->getMockBuilder(\Magento\Framework\Filesystem::class) ->disableOriginalConstructor() ->getMock(); @@ -70,8 +75,8 @@ public function setUp() ->getMock(); $this->componentRegistrarMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class); $this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([ - [ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']], - [ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']], + [ComponentRegistrar::MODULE, ['/path/to/module/one', '/path (1)/to/module/two']], + [ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path (1)/to/library/two']], ]); $this->command = new DiCompileCommand( @@ -128,7 +133,28 @@ public function testExecute() ->method('create') ->with(\Symfony\Component\Console\Helper\ProgressBar::class) ->willReturn($progressBar); - $this->managerMock->expects($this->exactly(7))->method('addOperation'); + + $this->managerMock->expects($this->exactly(7))->method('addOperation') + ->withConsecutive( + [OperationFactory::PROXY_GENERATOR, []], + [OperationFactory::REPOSITORY_GENERATOR, $this->anything()], + [OperationFactory::DATA_ATTRIBUTES_GENERATOR, []], + [OperationFactory::APPLICATION_CODE_GENERATOR, $this->callback(function ($subject) { + $this->assertEmpty(array_diff($subject['excludePatterns'], [ + "#^(?:/path \(1\)/to/setup/)(/[\w]+)*/Test#", + "#^(?:/path/to/library/one|/path \(1\)/to/library/two)/([\w]+/)?Test#", + "#^(?:/path/to/library/one|/path \(1\)/to/library/two)/([\w]+/)?tests#", + "#^(?:/path/to/(?:module/(?:one))|/path \(1\)/to/(?:module/(?:two)))/Test#", + "#^(?:/path/to/(?:module/(?:one))|/path \(1\)/to/(?:module/(?:two)))/tests#" + ])); + return true; + })], + [OperationFactory::INTERCEPTION, $this->anything()], + [OperationFactory::AREA_CONFIG_GENERATOR, $this->anything()], + [OperationFactory::INTERCEPTION_CACHE, $this->anything()] + ) + ; + $this->managerMock->expects($this->once())->method('process'); $tester = new CommandTester($this->command); $tester->execute([]);