コード例 #1
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());
 }
コード例 #2
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());
     }
 }
コード例 #3
0
 /**
  * Test get throws dependencies
  *
  * @test
  */
 public function testGetDependencies()
 {
     $tokens = [0 => [T_THROW, 'throw'], 1 => [T_WHITESPACE, ' '], 2 => [T_NEW, 'new'], 3 => [T_WHITESPACE, ' '], 4 => [T_NS_SEPARATOR, '\\'], 5 => [T_STRING, 'Exception'], 6 => '('];
     $this->tokens->expects($this->any())->method('getTokenCodeByKey')->will($this->returnCallback(function ($k) use($tokens) {
         return $tokens[$k][0];
     }));
     $this->tokens->expects($this->any())->method('getTokenValueByKey')->will($this->returnCallback(function ($k) use($tokens) {
         return $tokens[$k][1];
     }));
     $throws = new Throws($this->tokens);
     foreach ($tokens as $k => $token) {
         $throws->parse($token, $k);
     }
     $uses = $this->getMockBuilder('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\Uses')->disableOriginalConstructor()->getMock();
     $uses->expects($this->once())->method('hasUses')->will($this->returnValue(true));
     $uses->expects($this->once())->method('getClassNameWithNamespace')->will($this->returnValue('\\Exception'));
     $this->assertEquals(['\\Exception'], $throws->getDependencies($uses));
 }
コード例 #4
0
 /**
  * Test get static call dependencies
  *
  * @test
  */
 public function testGetDependencies()
 {
     $tokens = array(0 => array(T_WHITESPACE, ' '), 1 => array(T_NS_SEPARATOR, '\\'), 2 => array(T_STRING, 'Object'), 3 => array(T_PAAMAYIM_NEKUDOTAYIM, '::'));
     $this->tokens->expects($this->any())->method('getPreviousToken')->will($this->returnCallback(function ($k) use($tokens) {
         return $tokens[$k - 1];
     }));
     $this->tokens->expects($this->any())->method('getTokenCodeByKey')->will($this->returnCallback(function ($k) use($tokens) {
         return $tokens[$k][0];
     }));
     $this->tokens->expects($this->any())->method('getTokenValueByKey')->will($this->returnCallback(function ($k) use($tokens) {
         return $tokens[$k][1];
     }));
     $throws = new StaticCalls($this->tokens);
     foreach ($tokens as $k => $token) {
         $throws->parse($token, $k);
     }
     $uses = $this->getMockBuilder('Magento\\TestFramework\\Integrity\\Library\\PhpParser\\Uses')->disableOriginalConstructor()->getMock();
     $uses->expects($this->once())->method('hasUses')->will($this->returnValue(true));
     $uses->expects($this->once())->method('getClassNameWithNamespace')->will($this->returnValue('\\Object'));
     $this->assertEquals(array('\\Object'), $throws->getDependencies($uses));
 }
コード例 #5
0
 /**
  * Covered getTokenValueByKey
  *
  * @test
  */
 public function testGetTokenValueByKey()
 {
     $this->tokens = new Tokens($this->content, $this->parseFactory);
     $this->assertEquals('echo', $this->tokens->getTokenValueByKey(1));
 }