‪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;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪FunctionCallMatcherTest extends UnitTestCase
27 {
31  public function ‪hitsFromFixtureAreFound(): void
32  {
33  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
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 
65  public function ‪matchIsIgnoredIfIgnoreFileIsSet(): void
66  {
67  $phpCode = <<<'EOC'
68 <?php
73 class foo
74 {
75  public function aTest()
76  {
77  // This valid match should not match since the entire file is ignored
78  debugBegin();
79  }
80 }
81 EOC;
82 
83  ‪$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
84  $statements = ‪$parser->parse($phpCode);
85 
86  $traverser = new NodeTraverser();
87  $configuration = [
88  'debugBegin' => [
89  'numberOfMandatoryArguments' => 0,
90  'maximumNumberOfArguments' => 0,
91  'restFiles' => [
92  'Breaking-37180-RemovedExtDirectDebugAndGLOBALSerror.rst',
93  ],
94  ],
95  ];
96  $subject = new ‪FunctionCallMatcher($configuration);
97  $traverser->addVisitor($subject);
98  $traverser->traverse($statements);
99 
100  self::assertEmpty($subject->getMatches());
101  }
102 }
‪$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\FunctionCallMatcherTest\matchIsIgnoredIfIgnoreFileIsSet
‪matchIsIgnoredIfIgnoreFileIsSet()
Definition: FunctionCallMatcherTest.php:65
‪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:27