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