コード例 #1
0
    public function testExecute()
    {
        $this->objectManager->expects($this->once())
            ->method('get')
            ->with('Magento\Framework\App\Cache')
            ->willReturn($this->cacheMock);
        $this->cacheMock->expects($this->once())->method('clean');
        $writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface');
        $writeDirectory->expects($this->atLeastOnce())->method('delete');
        $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);

        $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
        $progressBar = $this->getMockBuilder(
            'Symfony\Component\Console\Helper\ProgressBar'
        )
            ->disableOriginalConstructor()
            ->getMock();

        $this->objectManager->expects($this->once())->method('configure');
        $this->objectManager
            ->expects($this->once())
            ->method('create')
            ->with('Symfony\Component\Console\Helper\ProgressBar')
            ->willReturn($progressBar);
        $this->manager->expects($this->exactly(6))->method('addOperation');
        $this->manager->expects($this->once())->method('process');
        $tester = new CommandTester($this->command);
        $tester->execute([]);
        $this->assertContains(
            'Generated code and dependency injection configuration successfully.',
            explode(PHP_EOL, $tester->getDisplay())
        );
    }
コード例 #2
0
 public function testExecute()
 {
     $this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\App\\Cache')->willReturn($this->cacheMock);
     $this->cacheMock->expects($this->once())->method('clean');
     $writeDirectory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $writeDirectory->expects($this->atLeastOnce())->method('delete');
     $this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
     $this->deploymentConfigMock->expects($this->once())->method('get')->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)->willReturn(['Magento_Catalog' => 1]);
     $progressBar = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\ProgressBar')->disableOriginalConstructor()->getMock();
     $this->objectManagerMock->expects($this->once())->method('configure');
     $this->objectManagerMock->expects($this->once())->method('create')->with('Symfony\\Component\\Console\\Helper\\ProgressBar')->willReturn($progressBar);
     $this->managerMock->expects($this->exactly(7))->method('addOperation');
     $this->managerMock->expects($this->once())->method('process');
     $tester = new CommandTester($this->command);
     $tester->execute([]);
     $this->assertContains('Generated code and dependency injection configuration successfully.', explode(PHP_EOL, $tester->getDisplay()));
     $this->assertSame(DiCompileCommand::NAME, $this->command->getName());
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $errors = $this->checkEnvironment();
     if ($errors) {
         foreach ($errors as $line) {
             $output->writeln($line);
         }
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
     $modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
     $libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
     $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
     $this->objectManager->get('Magento\\Framework\\App\\Cache')->clean();
     $compiledPathsList = ['application' => $modulePaths, 'library' => $libraryPaths, 'generated_helpers' => $generationPath];
     $excludedModulePaths = [];
     foreach ($modulePaths as $appCodePath) {
         $excludedModulePaths[] = '#^' . $appCodePath . '/Test#';
     }
     $excludedLibraryPaths = [];
     foreach ($libraryPaths as $libraryPath) {
         $excludedLibraryPaths[] = '#^' . $libraryPath . '/([\\w]+/)?Test#';
     }
     $this->excludedPathsList = ['application' => $excludedModulePaths, 'framework' => $excludedLibraryPaths];
     $this->configureObjectManager($output);
     $operations = $this->getOperationsConfiguration($compiledPathsList);
     try {
         $this->cleanupFilesystem([DirectoryList::CACHE, DirectoryList::DI]);
         foreach ($operations as $operationCode => $arguments) {
             $this->taskManager->addOperation($operationCode, $arguments);
         }
         /** @var ProgressBar $progressBar */
         $progressBar = $this->objectManager->create('Symfony\\Component\\Console\\Helper\\ProgressBar', ['output' => $output, 'max' => count($operations)]);
         $progressBar->setFormat('<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%');
         $output->writeln('<info>Compilation was started.</info>');
         $progressBar->start();
         $progressBar->display();
         $this->taskManager->process(function (OperationInterface $operation) use($progressBar) {
             $progressBar->setMessage($operation->getName() . '...');
             $progressBar->display();
         }, function (OperationInterface $operation) use($progressBar) {
             $progressBar->advance();
         });
         $progressBar->finish();
         $output->writeln('');
         $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
     } catch (OperationException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
 }
コード例 #4
0
    public function testExecute()
    {
        $this->objectManager->expects($this->once())
            ->method('get')
            ->with('Magento\Framework\App\Cache')
            ->willReturn($this->cacheMock);
        $this->cacheMock->expects($this->once())->method('clean');
        $writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface');
        $writeDirectory->expects($this->atLeastOnce())->method('delete');
        $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);

        $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
        $this->objectManager->expects($this->once())->method('configure');
        $this->manager->expects($this->exactly(6))->method('addOperation');
        $this->manager->expects($this->once())->method('process');
        $tester = new CommandTester($this->command);
        $tester->execute([]);
        $this->assertEquals(
            'Generated code and dependency injection configuration successfully.' . PHP_EOL,
            $tester->getDisplay()
        );
    }
コード例 #5
0
ファイル: DiCompileCommand.php プロジェクト: nja78/magento2
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES);
        $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL);
        $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
        if (!$this->deploymentConfig->isAvailable()) {
            $output->writeln('You cannot run this command because the Magento application is not installed.');
            return;
        }
        $this->objectManager->get('Magento\Framework\App\Cache')->clean();
        $compiledPathsList = [
            'application' => $appCodePath,
            'library' => $libraryPath . '/Magento/Framework',
            'generated_helpers' => $generationPath
        ];
        $this->excludedPathsList = [
            'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#',
            'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#'
        ];
        $dataAttributesIncludePattern = [
            'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/'
        ];
        $this->configureObjectManager($output);

        $operations = [
            OperationFactory::REPOSITORY_GENERATOR => [
                'path' => $compiledPathsList['application'],
                'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/']
            ],
            OperationFactory::DATA_ATTRIBUTES_GENERATOR => [
                'path' => $compiledPathsList['application'],
                'filePatterns' => $dataAttributesIncludePattern
            ],
            OperationFactory::APPLICATION_CODE_GENERATOR => [
                $compiledPathsList['application'],
                $compiledPathsList['library'],
                $compiledPathsList['generated_helpers'],
            ],
            OperationFactory::INTERCEPTION => [
                    'intercepted_paths' => [
                        $compiledPathsList['application'],
                        $compiledPathsList['library'],
                        $compiledPathsList['generated_helpers'],
                    ],
                    'path_to_store' => $compiledPathsList['generated_helpers'],
            ],
            OperationFactory::AREA_CONFIG_GENERATOR => [
                $compiledPathsList['application'],
                $compiledPathsList['library'],
                $compiledPathsList['generated_helpers'],
            ],
            OperationFactory::INTERCEPTION_CACHE => [
                $compiledPathsList['application'],
                $compiledPathsList['library'],
                $compiledPathsList['generated_helpers'],
            ]
        ];

        try {
            $this->cleanupFilesystem(
                [
                    DirectoryList::CACHE,
                    DirectoryList::GENERATION,
                    DirectoryList::DI,
                ]
            );
            foreach ($operations as $operationCode => $arguments) {
                $this->taskManager->addOperation(
                    $operationCode,
                    $arguments
                );
            }
            $this->taskManager->process();
            $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
        } catch (OperationException $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>');
        }
    }
コード例 #6
0
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES);
        $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL);
        $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
        if (!$this->deploymentConfig->isAvailable()) {
            $output->writeln('You cannot run this command because the Magento application is not installed.');
            return;
        }
        $this->objectManager->get('Magento\Framework\App\Cache')->clean();
        $compiledPathsList = [
            'application' => $appCodePath,
            'library' => $libraryPath . '/Magento/Framework',
            'generated_helpers' => $generationPath
        ];
        $this->excludedPathsList = [
            'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#',
            'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#'
        ];
        $dataAttributesIncludePattern = [
            'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/'
        ];
        $this->configureObjectManager($output);

        $operations = $this->getOperationsConfiguration(
            $compiledPathsList,
            $dataAttributesIncludePattern
        );

        try {
            $this->cleanupFilesystem(
                [
                    DirectoryList::CACHE,
                    DirectoryList::GENERATION,
                    DirectoryList::DI,
                ]
            );
            foreach ($operations as $operationCode => $arguments) {
                $this->taskManager->addOperation(
                    $operationCode,
                    $arguments
                );
            }

            /** @var ProgressBar $progressBar */
            $progressBar = $this->objectManager->create(
                'Symfony\Component\Console\Helper\ProgressBar',
                [
                    'output' => $output,
                    'max' => count($operations)
                ]
            );
            $progressBar->setFormat(
                '<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%'
            );
            $output->writeln('<info>Compilation was started.</info>');
            $progressBar->start();
            $progressBar->display();

            $this->taskManager->process(
                function (OperationInterface $operation) use ($progressBar) {
                    $progressBar->setMessage($operation->getName() . '...');
                    $progressBar->display();
                },
                function (OperationInterface $operation) use ($progressBar) {
                    $progressBar->advance();
                }
            );

            $progressBar->finish();
            $output->writeln('');
            $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
        } catch (OperationException $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>');
        }
    }