‪TYPO3CMS  10.4
ArrayDimensionMatcherTest.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;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪ArrayDimensionMatcherTest extends UnitTestCase
30 {
34  public function ‪hitsFromFixtureAreFound()
35  {
36  ‪$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
37  $fixtureFile = __DIR__ . '/Fixtures/ArrayDimensionMatcherFixture.php';
38  $statements = ‪$parser->parse(file_get_contents($fixtureFile));
39 
40  $traverser = new NodeTraverser();
41  $traverser->addVisitor(new NameResolver());
42 
43  $configuration = [
44  '$GLOBALS[\'TYPO3_CONF_VARS\'][\'FE\'][\'maxSessionDataSize\']' => [
45  'restFiles' => [
46  'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
47  'Deprecation-70316-FrontendBasketWithRecs.rst',
48  ],
49  ],
50  ];
51  $subject = new ‪ArrayDimensionMatcher($configuration);
52  $traverser->addVisitor($subject);
53  $traverser->traverse($statements);
54  $expectedHitLineNumbers = [
55  28,
56  29,
57  ];
58  $actualHitLineNumbers = [];
59  foreach ($subject->getMatches() as $hit) {
60  $actualHitLineNumbers[] = $hit['line'];
61  }
62  self::assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
63  }
64 
69  {
70  return [
71  'two candidates' => [
72  [
73  '$foo[\'bar\'][\'findMe\']' => [
74  'restFiles' => [
75  'Foo-1.rst',
76  'Foo-2.rst',
77  ],
78  ],
79  '$foo[\'findMe\']' => [
80  'restFiles' => [
81  'Bar-1.rst',
82  'Bar-2.rst',
83  ],
84  ],
85  ],
86  '<?php
87  $bar = $foo[\'findMe\'];',
88  [
89  0 => [
90  'restFiles' => [
91  'Foo-1.rst',
92  'Foo-2.rst',
93  'Bar-1.rst',
94  'Bar-2.rst',
95  ],
96  ],
97  ],
98  ],
99  'double linked .rst file is returned only once' => [
100  [
101  '$foo[\'bar\'][\'findMe\']' => [
102  'unusedArgumentNumbers' => [ 1 ],
103  'restFiles' => [
104  'aRest.rst',
105  ],
106  ],
107  '$foo[\'findMe\']' => [
108  'unusedArgumentNumbers' => [ 1 ],
109  'restFiles' => [
110  'aRest.rst',
111  ],
112  ],
113  ],
114  '<?php
115  $bar = $foo[\'findMe\'];',
116  [
117  0 => [
118  'restFiles' => [
119  'aRest.rst',
120  ],
121  ],
122  ],
123  ],
124  ];
125  }
126 
134  public function ‪matchesReturnsExpectedRestFiles(array $configuration, string $phpCode, array $expected)
135  {
136  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
137  $statements = ‪$parser->parse($phpCode);
138 
139  $subject = new ‪ArrayDimensionMatcher($configuration);
140 
141  $traverser = new NodeTraverser();
142  $traverser->addVisitor($subject);
143  $traverser->traverse($statements);
144 
145  $result = $subject->getMatches();
146  self::assertEquals($expected[0]['restFiles'], $result[0]['restFiles']);
147  }
148 }
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ArrayDimensionMatcherTest\matchesReturnsExpectedRestFiles
‪matchesReturnsExpectedRestFiles(array $configuration, string $phpCode, array $expected)
Definition: ArrayDimensionMatcherTest.php:134
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcherTest.php:18
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ArrayDimensionMatcherTest\hitsFromFixtureAreFound
‪hitsFromFixtureAreFound()
Definition: ArrayDimensionMatcherTest.php:34
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher
Definition: ArrayDimensionMatcher.php:31
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ArrayDimensionMatcherTest
Definition: ArrayDimensionMatcherTest.php:30
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ArrayDimensionMatcherTest\matchesReturnsExpectedRestFilesDataProvider
‪array matchesReturnsExpectedRestFilesDataProvider()
Definition: ArrayDimensionMatcherTest.php:68