Skip to content

Commit

Permalink
Generic/LowercasedFilename: improve code coverage (#681)
Browse files Browse the repository at this point in the history
Includes adding a test for handling STDIN per suggestion during code review.
  • Loading branch information
rodrigoprimo authored and jrfnl committed Nov 26, 2024
1 parent d95f2ad commit ef6882a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace PHP_CodeSniffer\Standards\Generic\Tests\Files;

use PHP_CodeSniffer\Files\DummyFile;
use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
Expand All @@ -20,6 +23,24 @@ final class LowercasedFilenameUnitTest extends AbstractSniffUnitTest
{


/**
* Get a list of all test files to check.
*
* @param string $testFileBase The base path that the unit tests files will have.
*
* @return string[]
*/
protected function getTestFiles($testFileBase)
{
$testFileDir = dirname($testFileBase);
$testFiles = parent::getTestFiles($testFileBase);
$testFiles[] = $testFileDir.DIRECTORY_SEPARATOR.'lowercased_filename_unit_test.inc';

return $testFiles;

}//end getTestFiles()


/**
* Returns the lines where errors should occur.
*
Expand Down Expand Up @@ -58,4 +79,28 @@ public function getWarningList()
}//end getWarningList()


/**
* Test the sniff bails early when handling STDIN.
*
* @return void
*/
public function testStdIn()
{
$config = new ConfigDouble();
$config->standards = ['Generic'];
$config->sniffs = ['Generic.Files.LowercasedFilename'];

$ruleset = new Ruleset($config);

$content = '<?php ';
$file = new DummyFile($content, $ruleset, $config);
$file->process();

$this->assertSame(0, $file->getErrorCount());
$this->assertSame(0, $file->getWarningCount());
$this->assertCount(0, $file->getErrors());

}//end testStdIn()


}//end class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php

0 comments on commit ef6882a

Please sign in to comment.