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