Skip to content

Commit f8639a2

Browse files
committed
Generic/OpeningFunctionBraceKernighanRichie: improve test coverage
1 parent bbfc68b commit f8639a2

6 files changed

+76
-0
lines changed

src/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.1.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,14 @@ function myFunction($a, $lot, $of, $params)
212212
function myFunction() {}
213213
function myFunction() {} // Too many spaces with an empty function.
214214
function myFunction() {} // Too many spaces (tab) with an empty function.
215+
216+
// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 0
217+
function shouldBeIgnored()
218+
{}
219+
// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 1
220+
221+
function dnfReturnType(): (Response&SuccessResponse)|AnotherResponse|string
222+
{}
223+
224+
function contentAfterOpeningBrace() { // Some comment.
225+
}

src/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.1.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,15 @@ function myFunction($a, $lot, $of, $params)
200200
function myFunction() {}
201201
function myFunction() {} // Too many spaces with an empty function.
202202
function myFunction() {} // Too many spaces (tab) with an empty function.
203+
204+
// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 0
205+
function shouldBeIgnored()
206+
{}
207+
// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 1
208+
209+
function dnfReturnType(): (Response&SuccessResponse)|AnotherResponse|string {
210+
}
211+
212+
function contentAfterOpeningBrace() {
213+
// Some comment.
214+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// Tests with tabs and the tabWidth config set to 4.
4+
5+
// Uses one tab.
6+
function myFunction() {
7+
}
8+
9+
// Uses three tabs.
10+
function myFunction() {
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// Tests with tabs and the tabWidth config set to 4.
4+
5+
// Uses one tab.
6+
function myFunction() {
7+
}
8+
9+
// Uses three tabs.
10+
function myFunction() {
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing opening parenthesis).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
function missingOpeningParenthesis

src/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ final class OpeningFunctionBraceKernighanRitchieUnitTest extends AbstractSniffUn
2020
{
2121

2222

23+
/**
24+
* Get a list of CLI values to set before the file is tested.
25+
*
26+
* @param string $testFile The name of the file being tested.
27+
* @param \PHP_CodeSniffer\Config $config The config data for the test run.
28+
*
29+
* @return void
30+
*/
31+
public function setCliValues($testFile, $config)
32+
{
33+
if ($testFile === 'OpeningFunctionBraceKernighanRitchieUnitTest.2.inc') {
34+
$config->tabWidth = 4;
35+
}
36+
37+
}//end setCliValues()
38+
39+
2340
/**
2441
* Returns the lines where errors should occur.
2542
*
@@ -63,6 +80,13 @@ public function getErrorList($testFile='')
6380
203 => 1,
6481
213 => 1,
6582
214 => 1,
83+
222 => 1,
84+
224 => 1,
85+
];
86+
case 'OpeningFunctionBraceKernighanRitchieUnitTest.2.inc':
87+
return [
88+
6 => 1,
89+
10 => 1,
6690
];
6791
default:
6892
return [];

0 commit comments

Comments
 (0)