[!!!][TASK] Remove TYPO3.jQuery
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / ExtensionScanner / Php / Matcher / ClassConstantMatcherTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher;
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;
21 use TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver;
22 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassConstantMatcher;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24
25 /**
26 * Test case
27 */
28 class ClassConstantMatcherTest extends UnitTestCase
29 {
30 /**
31 * @test
32 */
33 public function hitsFromFixtureAreFound()
34 {
35 $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
36 $fixtureFile = __DIR__ . '/Fixtures/ClassConstantMatcherFixture.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 'TYPO3\CMS\Backend\Template\DocumentTemplate::STATUS_ICON_ERROR' => [
45 'restFiles' => [
46 'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
47 ],
48 ],
49 'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT' => [
50 'restFiles' => [
51 'Breaking-82378-RemoveNamespacedJQuery.rst',
52 ],
53 ],
54 ];
55 $subject = new ClassConstantMatcher($configuration);
56 $traverser->addVisitor($subject);
57 $traverser->traverse($statements);
58 $expectedHitLineNumbers = [
59 28,
60 29,
61 30,
62 ];
63 $actualHitLineNumbers = [];
64 foreach ($subject->getMatches() as $hit) {
65 $actualHitLineNumbers[] = $hit['line'];
66 }
67 $this->assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
68 }
69
70 /**
71 * @return array
72 */
73 public function matchesReturnsExpectedRestFilesDataProvider()
74 {
75 return [
76 'a straight match' => [
77 [
78 'Foo\Bar::aClassConstant' => [
79 'restFiles' => [
80 'Foo-1.rst',
81 'Foo-2.rst',
82 ],
83 ],
84 ],
85 '<?php
86 $foo = \Foo\Bar::aClassConstant;',
87 [
88 0 => [
89 'restFiles' => [
90 'Foo-1.rst',
91 'Foo-2.rst',
92 ],
93 ],
94 ],
95 ],
96 ];
97 }
98
99 /**
100 * @test
101 * @dataProvider matchesReturnsExpectedRestFilesDataProvider
102 */
103 public function matchesReturnsExpectedRestFiles(array $configuration, string $phpCode, array $expected)
104 {
105 $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
106 $statements = $parser->parse($phpCode);
107
108 $subject = new ClassConstantMatcher($configuration);
109
110 $traverser = new NodeTraverser();
111 $traverser->addVisitor(new NameResolver());
112 $traverser->addVisitor($subject);
113 $traverser->traverse($statements);
114
115 $result = $subject->getMatches();
116 $this->assertSame($expected[0]['restFiles'], $result[0]['restFiles']);
117 }
118 }