‪TYPO3CMS  10.4
ClassNameMatcherTest.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\NodeTraverser;
21 use PhpParser\NodeVisitor\NameResolver;
22 use PhpParser\ParserFactory;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪ClassNameMatcherTest extends UnitTestCase
31 {
35  public function ‪hitsFromFixtureAreFound()
36  {
37  ‪$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
38  $fixtureFile = __DIR__ . '/Fixtures/ClassNameMatcherFixture.php';
39  $statements = ‪$parser->parse(file_get_contents($fixtureFile));
40 
41  $traverser = new NodeTraverser();
42  $traverser->addVisitor(new NameResolver());
43  $traverser->addVisitor(new ‪GeneratorClassesResolver());
44 
45  $configuration = [
46  'RemoveXSS' => [
47  'restFiles' => [
48  'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
49  'Deprecation-76164-DeprecateRemoveXSS.rst',
50  ],
51  ],
52  'TYPO3\CMS\Backend\Console\Application' => [
53  'restFiles' => [
54  'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
55  'Deprecation-80468-CommandLineInterfaceCliKeysAndCli_dispatchphpsh.rst',
56  ],
57  ],
58  ];
59  $subject = new ‪ClassNameMatcher($configuration);
60  $traverser->addVisitor($subject);
61  $traverser->traverse($statements);
62  $expectedHitLineNumbers = [
63  30,
64  30,
65  30,
66  32,
67  35,
68  36,
69  37,
70  38,
71  39,
72  40,
73  41,
74  42,
75  43,
76  44,
77  47,
78  48,
79  ];
80  $actualHitLineNumbers = [];
81  foreach ($subject->getMatches() as $match) {
82  $actualHitLineNumbers[] = $match['line'];
83  }
84  self::assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
85  }
86 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver
Definition: GeneratorClassesResolver.php:41
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ClassNameMatcherTest\hitsFromFixtureAreFound
‪hitsFromFixtureAreFound()
Definition: ClassNameMatcherTest.php:35
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcherTest.php:18
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassNameMatcher
Definition: ClassNameMatcher.php:28
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ClassNameMatcherTest
Definition: ClassNameMatcherTest.php:31