‪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  43,
55  ];
56  $actualHitLineNumbers = [];
57  foreach ($subject->getMatches() as $hit) {
58  $actualHitLineNumbers[] = $hit['line'];
59  }
60  self::assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
61  }
62 
63  #[Test]
64  public function ‪matchIsIgnoredIfIgnoreFileIsSet(): void
65  {
66  $phpCode = <<<'EOC'
67 <?php
72 class foo
73 {
74  public function aTest()
75  {
76  // This valid match should not match since the entire file is ignored
77  debugBegin();
78  }
79 }
80 EOC;
81 
82  $parser = (new ParserFactory())->createForVersion(PhpVersion::fromComponents(8, 2));
83  $statements = $parser->parse($phpCode);
84 
85  $traverser = new NodeTraverser();
86  $configuration = [
87  'debugBegin' => [
88  'numberOfMandatoryArguments' => 0,
89  'maximumNumberOfArguments' => 0,
90  'restFiles' => [
91  'Breaking-37180-RemovedExtDirectDebugAndGLOBALSerror.rst',
92  ],
93  ],
94  ];
95  $subject = new ‪FunctionCallMatcher($configuration);
96  $traverser->addVisitor($subject);
97  $traverser->traverse($statements);
98 
99  self::assertEmpty($subject->getMatches());
100  }
101 }
‪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:64
‪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