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