You are here

final public function CoderSniffUnitTest::testSniff in Coder 7.2

Tests the extending classes Sniff class.

File

coder_sniffer/Test/CoderSniffUnitTest.php, line 50

Class

CoderSniffUnitTest
An abstract class that all sniff unit tests must extend.

Code

public final function testSniff() {

  // Skip this test if we can't run in this environment.
  if ($this
    ->shouldSkipTest() === true) {
    $this
      ->markTestSkipped();
  }
  $testFiles = $this
    ->getTestFiles();
  $sniffCodes = $this
    ->getSniffCodes();
  self::$phpcs
    ->process(array(), 'coder_sniffer/Drupal', $sniffCodes);
  $failureMessages = array();
  foreach ($testFiles as $testFile) {
    try {
      $phpcsFile = self::$phpcs
        ->processFile($testFile);
    } catch (Exception $e) {
      $this
        ->fail('An unexpected exception has been caught: ' . $e
        ->getMessage());
    }
    $failures = $this
      ->generateFailureMessages($phpcsFile);
    $failureMessages = array_merge($failureMessages, $failures);
  }

  //end foreach
  if (empty($failureMessages) === false) {
    $this
      ->fail(implode(PHP_EOL, $failureMessages));
  }
}