‪TYPO3CMS  10.4
ClassConstantMatcherTest.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 ClassConstantMatcherTest extends UnitTestCase
31 {
35  public function hitsFromFixtureAreFound()
36  {
37  ‪$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
38  $fixtureFile = __DIR__ . '/Fixtures/ClassConstantMatcherFixture.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  'TYPO3\CMS\Backend\Template\DocumentTemplate::STATUS_ICON_ERROR' => [
47  'restFiles' => [
48  'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
49  ],
50  ],
51  'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT' => [
52  'restFiles' => [
53  'Breaking-82378-RemoveNamespacedJQuery.rst',
54  ],
55  ],
56  ];
57  $subject = new ClassConstantMatcher($configuration);
58  $traverser->addVisitor($subject);
59  $traverser->traverse($statements);
60  $expectedHitLineNumbers = [
61  30,
62  31,
63  32,
64  ];
65  $actualHitLineNumbers = [];
66  foreach ($subject->getMatches() as $hit) {
67  $actualHitLineNumbers[] = $hit['line'];
68  }
69  self::assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
70  }
71 
75  public function matchesReturnsExpectedRestFilesDataProvider()
76  {
77  return [
78  'a straight match' => [
79  [
80  'Foo\Bar::aClassConstant' => [
81  'restFiles' => [
82  'Foo-1.rst',
83  'Foo-2.rst',
84  ],
85  ],
86  ],
87  '<?php
88  $foo = \Foo\Bar::aClassConstant;',
89  [
90  0 => [
91  'restFiles' => [
92  'Foo-1.rst',
93  'Foo-2.rst',
94  ],
95  ],
96  ],
97  ],
98  ];
99  }
100 
105  public function matchesReturnsExpectedRestFiles(array $configuration, string $phpCode, array $expected)
106  {
107  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
108  $statements = ‪$parser->parse($phpCode);
109 
110  $subject = new ClassConstantMatcher($configuration);
111 
112  $traverser = new NodeTraverser();
113  $traverser->addVisitor(new NameResolver());
114  $traverser->addVisitor($subject);
115  $traverser->traverse($statements);
116 
117  $result = $subject->getMatches();
118  self::assertSame($expected[0]['restFiles'], $result[0]['restFiles']);
119  }
120 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver
Definition: GeneratorClassesResolver.php:41
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcherTest.php:18
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassConstantMatcher
Definition: ClassConstantMatcher.php:31