Skip to content

Commit 195346f

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/OpeningFunctionBraceKernighanRichie: improve test coverage
Includes removing unnecessary trailing spaces from empty lines in the test file.
1 parent 111d851 commit 195346f

6 files changed

+104
-12
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class myClass
2323
// Good.
2424
function myFunction() {
2525
}
26-
26+
2727
// Brace should be on same line.
2828
function myFunction()
2929
{
3030
}
31-
31+
3232
// Too many spaces.
3333
function myFunction() {
3434
}
35-
35+
3636
// Uses tab.
3737
function myFunction() {
3838
}
@@ -70,18 +70,18 @@ class myClass
7070
function myFunction($variable1, $variable2,
7171
$variable3, $variable4) {
7272
}
73-
73+
7474
// Brace should be on same line.
7575
function myFunction($variable1, $variable2,
7676
$variable3, $variable4)
7777
{
7878
}
79-
79+
8080
// Too many spaces.
8181
function myFunction($variable1, $variable2,
8282
$variable3, $variable4) {
8383
}
84-
84+
8585
// Uses tab.
8686
function myFunction($variable1, $variable2,
8787
$variable3, $variable4) {
@@ -212,3 +212,21 @@ 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 commentAfterOpeningBrace() { // Some comment.
225+
}
226+
227+
function variableAssignmentAfterOpeningBrace() { $a = 1;
228+
}
229+
230+
abstract class MyClass {
231+
abstract public function abstractMethod();
232+
}

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class myClass
2222
// Good.
2323
function myFunction() {
2424
}
25-
25+
2626
// Brace should be on same line.
2727
function myFunction() {
2828
}
29-
29+
3030
// Too many spaces.
3131
function myFunction() {
3232
}
33-
33+
3434
// Uses tab.
3535
function myFunction() {
3636
}
@@ -67,17 +67,17 @@ class myClass
6767
function myFunction($variable1, $variable2,
6868
$variable3, $variable4) {
6969
}
70-
70+
7171
// Brace should be on same line.
7272
function myFunction($variable1, $variable2,
7373
$variable3, $variable4) {
7474
}
75-
75+
7676
// Too many spaces.
7777
function myFunction($variable1, $variable2,
7878
$variable3, $variable4) {
7979
}
80-
80+
8181
// Uses tab.
8282
function myFunction($variable1, $variable2,
8383
$variable3, $variable4) {
@@ -200,3 +200,23 @@ 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 commentAfterOpeningBrace() {
213+
// Some comment.
214+
}
215+
216+
function variableAssignmentAfterOpeningBrace() {
217+
$a = 1;
218+
}
219+
220+
abstract class MyClass {
221+
abstract public function abstractMethod();
222+
}
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 curly brace).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
function missingOpeningCurlyBrace()

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

Lines changed: 25 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,14 @@ public function getErrorList($testFile='')
6380
203 => 1,
6481
213 => 1,
6582
214 => 1,
83+
222 => 1,
84+
224 => 1,
85+
227 => 1,
86+
];
87+
case 'OpeningFunctionBraceKernighanRitchieUnitTest.2.inc':
88+
return [
89+
6 => 1,
90+
10 => 1,
6691
];
6792
default:
6893
return [];

0 commit comments

Comments
 (0)