getContents(), new ParserFactory()); $tokens->parseContent(); $dependencies = array_merge( (new Injectable())->getDependencies($fileReflection), $tokens->getDependencies() ); $allowedNamespaces = str_replace('\\', '\\\\', implode('|', $this->getAllowedNamespaces())); $pattern = '#Magento\\\\(?!' . $allowedNamespaces . ').*#'; foreach ($dependencies as $dependency) { $dependencyPaths = explode('\\', $dependency); $dependencyPaths = array_slice($dependencyPaths, 2); $dependencyPath = implode('\\', $dependencyPaths); $libraryPaths = $componentRegistrar->getPaths(ComponentRegistrar::LIBRARY); foreach ($libraryPaths as $libraryPath) { $filePath = str_replace('\\', '/', $libraryPath . '/' . $dependencyPath . '.php'); if (preg_match($pattern, $dependency) && !file_exists($filePath)) { $this->errors[$fileReflection->getFileName()][] = $dependency; } } } if (!empty($this->errors)) { $this->fail($this->getFailMessage()); } }, $this->libraryDataProvider() ); } /** * @inheritdoc */ public function tearDown() { $this->errors = []; } /** * Prepare failed message * * @return string */ protected function getFailMessage() { $failMessage = ''; foreach ($this->errors as $class => $dependencies) { $failMessage .= $class . ' depends for non-library ' . (count($dependencies) > 1 ? 'classes ' : 'class '); foreach ($dependencies as $dependency) { $failMessage .= $dependency . ' '; } $failMessage = trim($failMessage) . PHP_EOL; } return $failMessage; } /** * Contains all library files * * @return array */ public function libraryDataProvider() { // @TODO: remove this code when class Magento\Framework\Data\Collection will fixed $componentRegistrar = new ComponentRegistrar(); include_once $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework') . '/Option/ArrayInterface.php'; $blackList = Files::init()->readLists(__DIR__ . '/_files/blacklist*.txt'); $dataProvider = Files::init()->getPhpFiles(Files::INCLUDE_LIBS | Files::AS_DATA_SET); foreach ($dataProvider as $key => $data) { if (in_array($data[0], $blackList)) { unset($dataProvider[$key]); } else { include_once $data[0]; } } return $dataProvider; } }