[!!!][TASK] Remove ExtJS Debugging and $GLOBALS['error']
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / ExtensionScanner / Php / Matcher / FunctionCallMatcherTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Install\Tests\Unit\ExtensionScanner\Php\Matcher;
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 TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class FunctionCallMatcherTest extends UnitTestCase
28 {
29 /**
30 * @test
31 */
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 28,
55 ];
56 $actualHitLineNumbers = [];
57 foreach ($subject->getMatches() as $hit) {
58 $actualHitLineNumbers[] = $hit['line'];
59 }
60 $this->assertEquals($expectedHitLineNumbers, $actualHitLineNumbers);
61 }
62
63 /**
64 * @test
65 */
66 public function matchIsIgnoredIfIgnoreFileIsSet()
67 {
68 $phpCode = <<<'EOC'
69 <?php
70 /**
71 * Some comment
72 * @extensionScannerIgnoreFile This file is ignored
73 */
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 }