public function testScan()
 {
     $phpFiles = ['one/file/php', 'two/file/php'];
     $configFiles = ['one/file/config', 'two/file/config'];
     $files = ['php' => $phpFiles, 'config' => $configFiles];
     $scannerPhp = $this->getMock('Magento\\Setup\\Module\\Di\\Code\\Scanner\\ScannerInterface');
     $scannerXml = $this->getMock('Magento\\Setup\\Module\\Di\\Code\\Scanner\\ScannerInterface');
     $scannerPhpExpected = ['Model_OneProxy', 'Model_TwoFactory'];
     $scannerXmlExpected = ['Model_OneProxy', 'Model_ThreeFactory'];
     $scannerPhp->expects($this->once())->method('collectEntities')->with($phpFiles)->will($this->returnValue($scannerPhpExpected));
     $scannerXml->expects($this->once())->method('collectEntities')->with($configFiles)->will($this->returnValue($scannerXmlExpected));
     $this->_model->addChild($scannerPhp, 'php');
     $this->_model->addChild($scannerXml, 'config');
     $actual = $this->_model->collectEntities($files);
     $expected = [$scannerPhpExpected, $scannerXmlExpected];
     $this->assertEquals($expected, array_values($actual));
 }
 /**
  * Compile Code
  *
  * @param string $generationDir
  * @param array $fileExcludePatterns
  * @param InputInterface $input
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function compileCode($generationDir, $fileExcludePatterns, $input)
 {
     $diDir = $input->getOption(self::INPUT_KEY_DI) ? $input->getOption(self::INPUT_KEY_DI) : $this->directoryList->getPath(DirectoryList::DI);
     $relationsFile = $diDir . '/relations.ser';
     $pluginDefFile = $diDir . '/plugins.ser';
     $compilationDirs = [$this->directoryList->getPath(DirectoryList::SETUP) . '/Magento/Setup/Module', $this->directoryList->getRoot() . '/dev/tools/Magento/Tools'];
     $compilationDirs = array_merge($compilationDirs, $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE), $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY));
     $serializer = $input->getOption(self::INPUT_KEY_SERIALIZER) == Igbinary::NAME ? new Igbinary() : new Standard();
     // 2.1 Code scan
     $validator = new \Magento\Framework\Code\Validator();
     $validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
     $validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
     $classesScanner = new \Magento\Setup\Module\Di\Code\Reader\ClassesScanner();
     $classesScanner->addExcludePatterns($fileExcludePatterns);
     $directoryInstancesNamesList = new \Magento\Setup\Module\Di\Code\Reader\Decorator\Directory($this->log, new \Magento\Framework\Code\Reader\ClassReader(), $classesScanner, $validator, $generationDir);
     foreach ($compilationDirs as $path) {
         if (is_readable($path)) {
             $directoryInstancesNamesList->getList($path);
         }
     }
     $inheritanceScanner = new Scanner\InheritanceInterceptorScanner();
     $this->entities['interceptors'] = $inheritanceScanner->collectEntities(get_declared_classes(), $this->entities['interceptors']);
     // 2.1.1 Generation of Proxy and Interceptor Classes
     foreach (['interceptors', 'di'] as $type) {
         foreach ($this->entities[$type] as $entityName) {
             switch ($this->generator->generateClass($entityName)) {
                 case \Magento\Framework\Code\Generator::GENERATION_SUCCESS:
                     $this->log->add(Log::GENERATION_SUCCESS, $entityName);
                     break;
                 case \Magento\Framework\Code\Generator::GENERATION_ERROR:
                     $this->log->add(Log::GENERATION_ERROR, $entityName);
                     break;
                 case \Magento\Framework\Code\Generator::GENERATION_SKIP:
                 default:
                     //no log
                     break;
             }
         }
     }
     //2.1.2 Compile relations for Proxy/Interceptor classes
     $directoryInstancesNamesList->getList($generationDir);
     $relations = $directoryInstancesNamesList->getRelations();
     // 2.2 Compression
     $relationsFileDir = dirname($relationsFile);
     if (!file_exists($relationsFileDir)) {
         mkdir($relationsFileDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
     }
     $relations = array_filter($relations);
     file_put_contents($relationsFile, $serializer->serialize($relations));
     // 3. Plugin Definition Compilation
     $pluginScanner = new Scanner\CompositeScanner();
     $pluginScanner->addChild(new Scanner\PluginScanner(), 'di');
     $pluginDefinitions = [];
     $pluginList = $pluginScanner->collectEntities($this->files);
     $pluginDefinitionList = new \Magento\Framework\Interception\Definition\Runtime();
     foreach ($pluginList as $type => $entityList) {
         foreach ($entityList as $entity) {
             $pluginDefinitions[ltrim($entity, '\\')] = $pluginDefinitionList->getMethodList($entity);
         }
     }
     $outputContent = $serializer->serialize($pluginDefinitions);
     $pluginDefFileDir = dirname($pluginDefFile);
     if (!file_exists($pluginDefFileDir)) {
         mkdir($pluginDefFileDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
     }
     file_put_contents($pluginDefFile, $outputContent);
 }