‪TYPO3CMS  10.4
GeneratorClassesResolverTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use PhpParser\Node\Name\FullyQualified;
21 use PhpParser\NodeTraverser;
22 use PhpParser\ParserFactory;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪GeneratorClassesResolverTest extends UnitTestCase
30 {
35  {
36  $phpCode = <<<'EOC'
37 <?php
38 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Does\\Not\\Exist');
39 EOC;
40  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
41  $statements = ‪$parser->parse($phpCode);
42  $traverser = new NodeTraverser();
43  $traverser->addVisitor(new ‪GeneratorClassesResolver());
44  $statements = $traverser->traverse($statements);
45  self::assertInstanceOf(FullyQualified::class, $statements[0]->expr->args[0]->value);
46  self::assertEquals(['TYPO3', 'CMS', 'Does', 'Not', 'Exist'], $statements[0]->expr->args[0]->value->parts);
47  }
48 
53  {
54  $phpCode = <<<'EOC'
55 <?php
56 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Does\\Not\\' . $foo);
57 EOC;
58  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
59  $statements = ‪$parser->parse($phpCode);
60  $traverser = new NodeTraverser();
61  $traverser->addVisitor(new ‪GeneratorClassesResolver());
62  $statements = $traverser->traverse($statements);
63  self::assertNotInstanceOf(FullyQualified::class, $statements[0]->expr->args[0]->value);
64  }
65 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver
Definition: GeneratorClassesResolver.php:41
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\GeneratorClassesResolverTest\visitorDoesNotTransformDynamicallyCreatesFullyQualifiedNameFromStringArgumentInMakeInstance
‪visitorDoesNotTransformDynamicallyCreatesFullyQualifiedNameFromStringArgumentInMakeInstance()
Definition: GeneratorClassesResolverTest.php:52
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php
Definition: CodeStatisticsTest.php:18
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\GeneratorClassesResolverTest
Definition: GeneratorClassesResolverTest.php:30
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\GeneratorClassesResolverTest\visitorCreatesFullyQualifiedNameFromStringArgumentInMakeInstance
‪visitorCreatesFullyQualifiedNameFromStringArgumentInMakeInstance()
Definition: GeneratorClassesResolverTest.php:34