Пример #1
0
 /**
  * Covered parse content
  *
  * @test
  */
 public function testParseContent()
 {
     $parser = $this->getMockBuilder('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\Parser')->getMockForAbstractClass();
     $this->parseFactory->expects($this->any())->method('createParsers')->will($this->returnValue(array($parser)));
     $this->tokens = new Tokens($this->content, $this->parseFactory);
     $this->tokens->parseContent();
 }
Пример #2
0
 /**
  * Covered parse content
  *
  * @test
  */
 public function testParseContent()
 {
     $parser = $this->getMock('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\ParserInterface');
     $this->parseFactory->expects($this->any())->method('createParsers')->will($this->returnValue([$parser]));
     $this->tokens = new Tokens($this->content, $this->parseFactory);
     $this->tokens->parseContent();
 }
Пример #3
0
 public function testCheckDependencies()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $componentRegistrar = new ComponentRegistrar();
         $fileReflection = new FileReflection($file);
         $tokens = new Tokens($fileReflection->getContents(), new ParserFactory());
         $tokens->parseContent();
         $dependencies = array_merge((new Injectable())->getDependencies($fileReflection), $tokens->getDependencies());
         $pattern = '#^(\\\\|)' . implode('|', $this->getForbiddenNamespaces()) . '\\\\#';
         foreach ($dependencies as $dependency) {
             $dependencyPaths = explode('/', $dependency);
             $dependencyPaths = array_slice($dependencyPaths, 2);
             $dependency = implode('\\', $dependencyPaths);
             $libraryPaths = $componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
             foreach ($libraryPaths as $libraryPath) {
                 $filePath = str_replace('\\', '/', $libraryPath . '/' . $dependency . '.php');
                 if (preg_match($pattern, $dependency) && !file_exists($filePath)) {
                     $this->errors[$fileReflection->getFileName()][] = $dependency;
                 }
             }
         }
         if (!empty($this->errors)) {
             $this->fail($this->getFailMessage());
         }
     }, $this->libraryDataProvider());
 }
Пример #4
0
 /**
  * Test check dependencies in library from application
  *
  * @test
  * @dataProvider libraryDataProvider
  */
 public function testCheckDependencies($file)
 {
     $fileReflection = new FileReflection($file);
     $tokens = new Tokens($fileReflection->getContents(), new ParserFactory());
     $tokens->parseContent();
     $dependencies = array_merge((new Injectable())->getDependencies($fileReflection), $tokens->getDependencies());
     foreach ($dependencies as $dependency) {
         if (preg_match('#^(\\\\|)' . implode('|', $this->getForbiddenNamespaces()) . '\\\\#', $dependency) && !file_exists(BP . '/lib/internal/' . str_replace('\\', '/', $dependency) . '.php')) {
             $this->errors[$fileReflection->getFileName()][] = $dependency;
         }
     }
     if ($this->hasErrors()) {
         $this->fail($this->getFailMessage());
     }
 }