‪TYPO3CMS  9.5
GeneratorClassesResolverTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use PhpParser\Node\Name\FullyQualified;
19 use PhpParser\NodeTraverser;
20 use PhpParser\ParserFactory;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪GeneratorClassesResolverTest extends UnitTestCase
28 {
33  {
34  $phpCode = <<<'EOC'
35 <?php
36 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Does\\Not\\Exist');
37 EOC;
38  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
39  $statements = ‪$parser->parse($phpCode);
40  $traverser = new NodeTraverser();
41  $traverser->addVisitor(new ‪GeneratorClassesResolver());
42  $statements = $traverser->traverse($statements);
43  $this->assertInstanceOf(FullyQualified::class, $statements[0]->expr->args[0]->value);
44  $this->assertEquals(['TYPO3', 'CMS', 'Does', 'Not', 'Exist'], $statements[0]->expr->args[0]->value->parts);
45  }
46 
51  {
52  $phpCode = <<<'EOC'
53 <?php
54 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Does\\Not\\' . $foo);
55 EOC;
56  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
57  $statements = ‪$parser->parse($phpCode);
58  $traverser = new NodeTraverser();
59  $traverser->addVisitor(new ‪GeneratorClassesResolver());
60  $statements = $traverser->traverse($statements);
61  $this->assertNotInstanceOf(FullyQualified::class, $statements[0]->expr->args[0]->value);
62  }
63 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver
Definition: GeneratorClassesResolver.php:39
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\GeneratorClassesResolverTest\visitorDoesNotTransformDynamicallyCreatesFullyQualifiedNameFromStringArgumentInMakeInstance
‪visitorDoesNotTransformDynamicallyCreatesFullyQualifiedNameFromStringArgumentInMakeInstance()
Definition: GeneratorClassesResolverTest.php:50
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php
Definition: CodeStatisticsTest.php:3
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\GeneratorClassesResolverTest
Definition: GeneratorClassesResolverTest.php:28
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\GeneratorClassesResolverTest\visitorCreatesFullyQualifiedNameFromStringArgumentInMakeInstance
‪visitorCreatesFullyQualifiedNameFromStringArgumentInMakeInstance()
Definition: GeneratorClassesResolverTest.php:32