‪TYPO3CMS  ‪main
FunctionCallMatcherTest.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 PhpParser\PhpVersion;
24 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪FunctionCallMatcherTest extends UnitTestCase
29 {
30  #[Test]
31  public function ‪hitsFromFixtureAreFound(): void
32  {
33  ‪$parser = (new ParserFactory())->createForVersion(PhpVersion::fromComponents(8, 2));
34  $fixtureFile = __DIR__ . '/Fixtures/FunctionCallMatcherFixture.php';
35  $statements = ‪$parser->parse(file_get_contents($fixtureFile));
36 
37  $traverser = new NodeTraverser();
38  $traverser->addVisitor(new NameResolver());
39 
40  $configuration = [
41  'debugBegin' => [
42  'numberOfMandatoryArguments' => 0,
43  'maximumNumberOfArguments' => 0,
44  'restFiles' => [
45  'Breaking-37180-RemovedExtDirectDebugAndGLOBALSerror.rst',
46  ],
47  ],
48  ];
49  $subject = new ‪FunctionCallMatcher($configuration);
50  $traverser->addVisitor($subject);
51  $traverser->traverse($statements);
52  $expectedHitLineNumbers = [
53  28,
54  ];
55  $actualHitLineNumbers = [];
56  foreach ($subject->getMatches() as $hit) {
57  $actualHitLineNumbers[] = $hit['line'];
58  }
59  self::assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
60  }
61 
62  #[Test]
63  public function ‪matchIsIgnoredIfIgnoreFileIsSet(): void
64  {
65  $phpCode = <<<'EOC'
66 <?php
71 class foo
72 {
73  public function aTest()
74  {
75  // This valid match should not match since the entire file is ignored
76  debugBegin();
77  }
78 }
79 EOC;
80 
81  ‪$parser = (new ParserFactory())->createForVersion(PhpVersion::fromComponents(8, 2));
82  $statements = ‪$parser->parse($phpCode);
83 
84  $traverser = new NodeTraverser();
85  $configuration = [
86  'debugBegin' => [
87  'numberOfMandatoryArguments' => 0,
88  'maximumNumberOfArguments' => 0,
89  'restFiles' => [
90  'Breaking-37180-RemovedExtDirectDebugAndGLOBALSerror.rst',
91  ],
92  ],
93  ];
94  $subject = new ‪FunctionCallMatcher($configuration);
95  $traverser->addVisitor($subject);
96  $traverser->traverse($statements);
97 
98  self::assertEmpty($subject->getMatches());
99  }
100 }
‪$parser
‪$parser
Definition: annotationChecker.php:103
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcherTest.php:18
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\FunctionCallMatcherTest\matchIsIgnoredIfIgnoreFileIsSet
‪matchIsIgnoredIfIgnoreFileIsSet()
Definition: FunctionCallMatcherTest.php:63
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher
Definition: FunctionCallMatcher.php:30
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\FunctionCallMatcherTest\hitsFromFixtureAreFound
‪hitsFromFixtureAreFound()
Definition: FunctionCallMatcherTest.php:31
‪TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher\FunctionCallMatcherTest
Definition: FunctionCallMatcherTest.php:29