Skip to content

Commit 0deed7b

Browse files
committed
Add test for using a namespace in sitePassByRefFunctions
1 parent 5e2f18e commit 0deed7b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Tests/VariableAnalysisSniff/VariableAnalysisTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ public function testFunctionWithReferenceWarnings()
298298
77,
299299
81,
300300
98,
301+
106,
301302
];
302303
$this->assertSame($expectedWarnings, $lines);
303304
}
@@ -331,6 +332,36 @@ public function testFunctionWithReferenceWarningsAllowsCustomFunctions()
331332
$this->assertSame($expectedWarnings, $lines);
332333
}
333334

335+
public function testFunctionWithReferenceWarningsAllowsCustomFunctionsNamespaced()
336+
{
337+
$fixtureFile = $this->getFixture('FunctionWithReferenceFixture.php');
338+
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
339+
$this->setSniffProperty($phpcsFile, 'sitePassByRefFunctions', '\My\Functions\my_reference_function:2,3 another_reference_function:2,...');
340+
$phpcsFile->process();
341+
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
342+
$expectedWarnings = [
343+
10,
344+
11,
345+
12,
346+
13,
347+
14,
348+
16,
349+
29,
350+
41,
351+
42,
352+
43,
353+
46,
354+
52,
355+
56,
356+
57,
357+
63,
358+
76,
359+
81,
360+
98,
361+
];
362+
$this->assertSame($expectedWarnings, $lines);
363+
}
364+
334365
public function testFunctionWithReferenceWarningsAllowsWordPressFunctionsIfSet()
335366
{
336367
$fixtureFile = $this->getFixture('FunctionWithReferenceFixture.php');
@@ -357,6 +388,7 @@ public function testFunctionWithReferenceWarningsAllowsWordPressFunctionsIfSet()
357388
76,
358389
77,
359390
98,
391+
106,
360392
];
361393
$this->assertSame($expectedWarnings, $lines);
362394
}

Tests/VariableAnalysisSniff/fixtures/FunctionWithReferenceFixture.php

+5
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ function function_with_foreach_with_reference($derivatives, $base_plugin_definit
100100
}
101101
return $derivatives;
102102
}
103+
104+
function function_with_ignored_reference_call_with_namespace() {
105+
$foo = 'bar';
106+
\My\Functions\my_reference_function($foo, $baz, $bip); // Undefined variable $bar, Undefined variable $bip
107+
}

0 commit comments

Comments
 (0)