Beispiel #1
0
 /**
  * Covered getDependencies method
  *
  * @test
  */
 public function testGetDependencies()
 {
     $uses = $this->getMockBuilder('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\Uses')->disableOriginalConstructor()->getMock();
     $this->parseFactory->expects($this->exactly(2))->method('getUses')->will($this->returnValue($uses));
     $staticCalls = $this->getMockBuilder('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\StaticCalls')->disableOriginalConstructor()->getMock();
     $staticCalls->expects($this->once())->method('getDependencies')->will($this->returnValue(array('StaticDependency')));
     $this->parseFactory->expects($this->once())->method('getStaticCalls')->will($this->returnValue($staticCalls));
     $throws = $this->getMockBuilder('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\Throws')->disableOriginalConstructor()->getMock();
     $throws->expects($this->once())->method('getDependencies')->will($this->returnValue(array('ThrowDependency')));
     $this->parseFactory->expects($this->once())->method('getThrows')->will($this->returnValue($throws));
     $this->tokens = new Tokens($this->content, $this->parseFactory);
     $this->assertEquals(array('StaticDependency', 'ThrowDependency'), $this->tokens->getDependencies());
 }
 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());
 }
 /**
  * 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());
     }
 }