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