Skip to content

Commit 00cb442

Browse files
committed
Add test for handling STDIN per suggestion during code review
1 parent adc6510 commit 00cb442

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(File $phpcsFile, $stackPtr)
4444
{
4545
$filename = $phpcsFile->getFilename();
4646
if ($filename === 'STDIN') {
47-
return $phpcsFile->numTokens; // @codeCoverageIgnore
47+
return $phpcsFile->numTokens;
4848
}
4949

5050
$filename = basename($filename);

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

Lines changed: 27 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
/**
@@ -76,4 +79,28 @@ public function getWarningList()
7679
}//end getWarningList()
7780

7881

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+
79106
}//end class

0 commit comments

Comments
 (0)