Skip to content

Commit

Permalink
Generic/OpeningFunctionBraceKernighanRichie: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoprimo committed Nov 21, 2024
1 parent bbfc68b commit f8639a2
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,14 @@ function myFunction($a, $lot, $of, $params)
function myFunction() {}
function myFunction() {} // Too many spaces with an empty function.
function myFunction() {} // Too many spaces (tab) with an empty function.

// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 0
function shouldBeIgnored()
{}
// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 1

function dnfReturnType(): (Response&SuccessResponse)|AnotherResponse|string
{}

function contentAfterOpeningBrace() { // Some comment.
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,15 @@ function myFunction($a, $lot, $of, $params)
function myFunction() {}
function myFunction() {} // Too many spaces with an empty function.
function myFunction() {} // Too many spaces (tab) with an empty function.

// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 0
function shouldBeIgnored()
{}
// phpcs:set Generic.Functions.OpeningFunctionBraceKernighanRitchie checkFunctions 1

function dnfReturnType(): (Response&SuccessResponse)|AnotherResponse|string {
}

function contentAfterOpeningBrace() {
// Some comment.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

// Tests with tabs and the tabWidth config set to 4.

// Uses one tab.
function myFunction() {
}

// Uses three tabs.
function myFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

// Tests with tabs and the tabWidth config set to 4.

// Uses one tab.
function myFunction() {
}

// Uses three tabs.
function myFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (missing opening parenthesis).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

function missingOpeningParenthesis
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ final class OpeningFunctionBraceKernighanRitchieUnitTest extends AbstractSniffUn
{


/**
* Get a list of CLI values to set before the file is tested.
*
* @param string $testFile The name of the file being tested.
* @param \PHP_CodeSniffer\Config $config The config data for the test run.
*
* @return void
*/
public function setCliValues($testFile, $config)
{
if ($testFile === 'OpeningFunctionBraceKernighanRitchieUnitTest.2.inc') {
$config->tabWidth = 4;
}

}//end setCliValues()


/**
* Returns the lines where errors should occur.
*
Expand Down Expand Up @@ -63,6 +80,13 @@ public function getErrorList($testFile='')
203 => 1,
213 => 1,
214 => 1,
222 => 1,
224 => 1,
];
case 'OpeningFunctionBraceKernighanRitchieUnitTest.2.inc':
return [
6 => 1,
10 => 1,
];
default:
return [];
Expand Down

0 comments on commit f8639a2

Please sign in to comment.