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