‪TYPO3CMS  ‪main
PropertyAnnotationMatcherTest.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;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪PropertyAnnotationMatcherTest extends UnitTestCase
29 {
30  #[Test]
31  public function ‪hitsFromFixtureAreFound(): void
32  {
33  ‪$parser = (new ParserFactory())->createForVersion(PhpVersion::fromComponents(8, 2));
34  $fixtureFile = __DIR__ . '/Fixtures/PropertyAnnotationMatcherFixture.php';
35  $statements = ‪$parser->parse(file_get_contents($fixtureFile));
36 
37  $traverser = new NodeTraverser();
38  $traverser->addVisitor(new NameResolver());
39 
40  $configuration = [
41  '@inject' => [
42  'restFiles' => [
43  'Feature-82869-ReplaceInjectWithTYPO3CMSExtbaseAnnotationInject.rst',
44  'Deprecation-82869-ReplaceInjectWithTYPO3CMSExtbaseAnnotationInject.rst',
45  ],
46  ],
47  ];
48  $subject = new ‪PropertyAnnotationMatcher($configuration);
49  $traverser->addVisitor($subject);
50  $traverser->traverse($statements);
51  $expectedHitLineNumbers = [
52  28,
53  ];
54  $actualHitLineNumbers = [];
55  foreach ($subject->getMatches() as $hit) {
56  $actualHitLineNumbers[] = $hit['line'];
57  }
58  self::assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
59  }
60 }
‪$parser
‪$parser
Definition: annotationChecker.php:103
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcherTest\hitsFromFixtureAreFound
‪hitsFromFixtureAreFound()
Definition: PropertyAnnotationMatcherTest.php:31
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcherTest.php:18
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcher
Definition: PropertyAnnotationMatcher.php:30
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcherTest
Definition: PropertyAnnotationMatcherTest.php:29