‪TYPO3CMS  10.4
ConstructorArgumentMatcherTest.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;
23 use PHPUnit\Framework\TestCase;
27 
31 class ‪ConstructorArgumentMatcherTest extends TestCase
32 {
33  public function ‪hitsFromFixtureAreFoundDataProvider(): array
34  {
35  $defaults = [
36  'restFiles' => [
37  'Breaking-87193-DeprecatedFunctionalityRemoved.rst',
38  ],
39  ];
40 
41  return [
42  'required' => [
43  [
44  'required' => array_merge($defaults, [
45  'numberOfMandatoryArguments' => 4,
46  ]),
47  ],
48  [34, 35, 36, 37, 44, 45],
49  ],
50  'dropped' => [
51  [
52  'dropped' => array_merge($defaults, [
53  'maximumNumberOfArguments' => 2,
54  ]),
55  ],
56  [34, 35, 36, 37, 44, 45],
57  ],
58  'called' => [
59  [
60  'called' => array_merge($defaults, [
61  'numberOfMandatoryArguments' => 1,
62  'maximumNumberOfArguments' => 3,
63  ]),
64  ],
65  [34, 35, 36, 37, 44, 45],
66  ],
67  'unused' => [
68  [
69  'unused' => array_merge($defaults, [
70  'unusedArgumentNumbers' => [2],
71  ]),
72  ],
73  [34, 35, 36, 37],
74  ],
75  ];
76  }
77 
85  public function ‪hitsFromFixtureAreFound(array $configuration, array $expectation)
86  {
87  ‪$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
88  $fixtureFile = __DIR__ . '/Fixtures/ConstructorArgumentMatcherFixture.php';
89  $statements = ‪$parser->parse(file_get_contents($fixtureFile));
90 
91  // first process completely to resolve fully qualified names of arguments
92  $traverser = new NodeTraverser();
93  $traverser->addVisitor(new NameResolver());
94  $statements = $traverser->traverse($statements);
95 
96  // second process to actually work on the pre-resolved statements
97  $traverser = new NodeTraverser();
98  $traverser->addVisitor(new ‪GeneratorClassesResolver());
99  $subject = new ‪ConstructorArgumentMatcher([
100  Subject::class => $configuration
101  ]);
102  $traverser->addVisitor($subject);
103  $traverser->traverse($statements);
104 
105  $lineNumbers = array_column($subject->getMatches(), 'line');
106  self::assertEquals($expectation, $lineNumbers);
107  }
108 }
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ConstructorArgumentMatcherTest
Definition: ConstructorArgumentMatcherTest.php:32
‪TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver
Definition: GeneratorClassesResolver.php:41
‪$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\ConstructorArgumentMatcherTest\hitsFromFixtureAreFoundDataProvider
‪hitsFromFixtureAreFoundDataProvider()
Definition: ConstructorArgumentMatcherTest.php:33
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ConstructorArgumentMatcher
Definition: ConstructorArgumentMatcher.php:37
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\Fixtures\Subject
Definition: Subject.php:24
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\ConstructorArgumentMatcherTest\hitsFromFixtureAreFound
‪hitsFromFixtureAreFound(array $configuration, array $expectation)
Definition: ConstructorArgumentMatcherTest.php:85