Skip to content

Commit 609ac10

Browse files
authored
Generic/LowercasedFilename: improve code coverage (#681)
Includes adding a test for handling STDIN per suggestion during code review.
1 parent 823dc9a commit 609ac10

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
namespace PHP_CodeSniffer\Standards\Generic\Tests\Files;
1111

12+
use PHP_CodeSniffer\Files\DummyFile;
13+
use PHP_CodeSniffer\Ruleset;
14+
use PHP_CodeSniffer\Tests\ConfigDouble;
1215
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
1316

1417
/**
@@ -20,6 +23,24 @@ final class LowercasedFilenameUnitTest extends AbstractSniffUnitTest
2023
{
2124

2225

26+
/**
27+
* Get a list of all test files to check.
28+
*
29+
* @param string $testFileBase The base path that the unit tests files will have.
30+
*
31+
* @return string[]
32+
*/
33+
protected function getTestFiles($testFileBase)
34+
{
35+
$testFileDir = dirname($testFileBase);
36+
$testFiles = parent::getTestFiles($testFileBase);
37+
$testFiles[] = $testFileDir.DIRECTORY_SEPARATOR.'lowercased_filename_unit_test.inc';
38+
39+
return $testFiles;
40+
41+
}//end getTestFiles()
42+
43+
2344
/**
2445
* Returns the lines where errors should occur.
2546
*
@@ -58,4 +79,28 @@ public function getWarningList()
5879
}//end getWarningList()
5980

6081

82+
/**
83+
* Test the sniff bails early when handling STDIN.
84+
*
85+
* @return void
86+
*/
87+
public function testStdIn()
88+
{
89+
$config = new ConfigDouble();
90+
$config->standards = ['Generic'];
91+
$config->sniffs = ['Generic.Files.LowercasedFilename'];
92+
93+
$ruleset = new Ruleset($config);
94+
95+
$content = '<?php ';
96+
$file = new DummyFile($content, $ruleset, $config);
97+
$file->process();
98+
99+
$this->assertSame(0, $file->getErrorCount());
100+
$this->assertSame(0, $file->getWarningCount());
101+
$this->assertCount(0, $file->getErrors());
102+
103+
}//end testStdIn()
104+
105+
61106
}//end class
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

0 commit comments

Comments
 (0)