Skip to content

Commit

Permalink
When passing content directly to PHPCS, the file will still be added …
Browse files Browse the repository at this point in the history
…even when using the ignore file comment, but errors should still be suppressed.
  • Loading branch information
gsherwood committed Aug 30, 2013
1 parent 4c3c7b0 commit 50382ee
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/Core/ErrorSuppressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,34 @@ public function testSuppressWarning()
public function testSuppressFile()
{
$phpcs = new PHP_CodeSniffer();
$phpcs->setTokenListeners('Squiz', array('Squiz_Sniffs_Commenting_FileCommentSniff'));
$phpcs->setTokenListeners('Squiz', array('Generic_Sniffs_Commenting_TodoSniff'));
$phpcs->populateTokenListeners();

// Process without suppression.
$content = '<?php '.PHP_EOL.'$var = FALSE;';
$content = '<?php '.PHP_EOL.'//TODO: write some code';
$phpcs->processFile('noSuppressionTest.php', $content);

$files = $phpcs->getFiles();
$file = $files[0];

$errors = $file->getErrors();
$numErrors = $file->getErrorCount();
$this->assertEquals(1, $numErrors);
$this->assertEquals(1, count($errors));
$this->assertEquals(1, count($files));
$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(1, $numWarnings);
$this->assertEquals(1, count($warnings));

// Process with suppression.
$content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreFile'.PHP_EOL.'$var = FALSE;';
$content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreFile'.PHP_EOL.'//TODO: write some code';
$phpcs->processFile('suppressionTest.php', $content);

// The file shouldn't even be added to the $files array.
$files = $phpcs->getFiles();
$this->assertEquals(1, count($files));
$file = $files[1];

$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(0, $numWarnings);
$this->assertEquals(0, count($warnings));

}//end testSupressError()
}//end testSuppressFile()


}//end class
Expand Down

0 comments on commit 50382ee

Please sign in to comment.