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