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