You are here

class PHPUnit_Util_Log_TAP in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/Log/TAP.php \PHPUnit_Util_Log_TAP

A TestListener that generates a logfile of the test execution using the Test Anything Protocol (TAP).

@since Class available since Release 3.0.0

Hierarchy

Expanded class hierarchy of PHPUnit_Util_Log_TAP

1 string reference to 'PHPUnit_Util_Log_TAP'
PHPUnit_TextUI_Command::handleArguments in vendor/phpunit/phpunit/src/TextUI/Command.php
Handles the command-line arguments.

File

vendor/phpunit/phpunit/src/Util/Log/TAP.php, line 17

View source
class PHPUnit_Util_Log_TAP extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener {

  /**
   * @var int
   */
  protected $testNumber = 0;

  /**
   * @var int
   */
  protected $testSuiteLevel = 0;

  /**
   * @var bool
   */
  protected $testSuccessful = true;

  /**
   * Constructor.
   *
   * @param  mixed                       $out
   * @throws PHPUnit_Framework_Exception
   * @since  Method available since Release 3.3.4
   */
  public function __construct($out = null) {
    parent::__construct($out);
    $this
      ->write("TAP version 13\n");
  }

  /**
   * An error occurred.
   *
   * @param PHPUnit_Framework_Test $test
   * @param Exception              $e
   * @param float                  $time
   */
  public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
    $this
      ->writeNotOk($test, 'Error');
  }

  /**
   * A failure occurred.
   *
   * @param PHPUnit_Framework_Test                 $test
   * @param PHPUnit_Framework_AssertionFailedError $e
   * @param float                                  $time
   */
  public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
    $this
      ->writeNotOk($test, 'Failure');
    $message = explode("\n", PHPUnit_Framework_TestFailure::exceptionToString($e));
    $diagnostic = array(
      'message' => $message[0],
      'severity' => 'fail',
    );
    if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
      $cf = $e
        ->getComparisonFailure();
      if ($cf !== null) {
        $diagnostic['data'] = array(
          'got' => $cf
            ->getActual(),
          'expected' => $cf
            ->getExpected(),
        );
      }
    }
    $yaml = new Symfony\Component\Yaml\Dumper();
    $this
      ->write(sprintf("  ---\n%s  ...\n", $yaml
      ->dump($diagnostic, 2, 2)));
  }

  /**
   * Incomplete test.
   *
   * @param PHPUnit_Framework_Test $test
   * @param Exception              $e
   * @param float                  $time
   */
  public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
    $this
      ->writeNotOk($test, '', 'TODO Incomplete Test');
  }

  /**
   * Risky test.
   *
   * @param PHPUnit_Framework_Test $test
   * @param Exception              $e
   * @param float                  $time
   * @since  Method available since Release 4.0.0
   */
  public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
    $this
      ->write(sprintf("ok %d - # RISKY%s\n", $this->testNumber, $e
      ->getMessage() != '' ? ' ' . $e
      ->getMessage() : ''));
    $this->testSuccessful = false;
  }

  /**
   * Skipped test.
   *
   * @param PHPUnit_Framework_Test $test
   * @param Exception              $e
   * @param float                  $time
   * @since  Method available since Release 3.0.0
   */
  public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
    $this
      ->write(sprintf("ok %d - # SKIP%s\n", $this->testNumber, $e
      ->getMessage() != '' ? ' ' . $e
      ->getMessage() : ''));
    $this->testSuccessful = false;
  }

  /**
   * A testsuite started.
   *
   * @param PHPUnit_Framework_TestSuite $suite
   */
  public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
    $this->testSuiteLevel++;
  }

  /**
   * A testsuite ended.
   *
   * @param PHPUnit_Framework_TestSuite $suite
   */
  public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
    $this->testSuiteLevel--;
    if ($this->testSuiteLevel == 0) {
      $this
        ->write(sprintf("1..%d\n", $this->testNumber));
    }
  }

  /**
   * A test started.
   *
   * @param PHPUnit_Framework_Test $test
   */
  public function startTest(PHPUnit_Framework_Test $test) {
    $this->testNumber++;
    $this->testSuccessful = true;
  }

  /**
   * A test ended.
   *
   * @param PHPUnit_Framework_Test $test
   * @param float                  $time
   */
  public function endTest(PHPUnit_Framework_Test $test, $time) {
    if ($this->testSuccessful === true) {
      $this
        ->write(sprintf("ok %d - %s\n", $this->testNumber, PHPUnit_Util_Test::describe($test)));
    }
    $this
      ->writeDiagnostics($test);
  }

  /**
   * @param PHPUnit_Framework_Test $test
   * @param string                 $prefix
   * @param string                 $directive
   */
  protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') {
    $this
      ->write(sprintf("not ok %d - %s%s%s\n", $this->testNumber, $prefix != '' ? $prefix . ': ' : '', PHPUnit_Util_Test::describe($test), $directive != '' ? ' # ' . $directive : ''));
    $this->testSuccessful = false;
  }

  /**
   * @param PHPUnit_Framework_Test $test
   */
  private function writeDiagnostics(PHPUnit_Framework_Test $test) {
    if (!$test instanceof PHPUnit_Framework_TestCase) {
      return;
    }
    if (!$test
      ->hasOutput()) {
      return;
    }
    foreach (explode("\n", trim($test
      ->getActualOutput())) as $line) {
      $this
        ->write(sprintf("# %s\n", $line));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PHPUnit_Util_Log_TAP::$testNumber protected property
PHPUnit_Util_Log_TAP::$testSuccessful protected property
PHPUnit_Util_Log_TAP::$testSuiteLevel protected property
PHPUnit_Util_Log_TAP::addError public function An error occurred. Overrides PHPUnit_Framework_TestListener::addError
PHPUnit_Util_Log_TAP::addFailure public function A failure occurred. Overrides PHPUnit_Framework_TestListener::addFailure
PHPUnit_Util_Log_TAP::addIncompleteTest public function Incomplete test. Overrides PHPUnit_Framework_TestListener::addIncompleteTest
PHPUnit_Util_Log_TAP::addRiskyTest public function Risky test. Overrides PHPUnit_Framework_TestListener::addRiskyTest
PHPUnit_Util_Log_TAP::addSkippedTest public function Skipped test. Overrides PHPUnit_Framework_TestListener::addSkippedTest
PHPUnit_Util_Log_TAP::endTest public function A test ended. Overrides PHPUnit_Framework_TestListener::endTest
PHPUnit_Util_Log_TAP::endTestSuite public function A testsuite ended. Overrides PHPUnit_Framework_TestListener::endTestSuite
PHPUnit_Util_Log_TAP::startTest public function A test started. Overrides PHPUnit_Framework_TestListener::startTest
PHPUnit_Util_Log_TAP::startTestSuite public function A testsuite started. Overrides PHPUnit_Framework_TestListener::startTestSuite
PHPUnit_Util_Log_TAP::writeDiagnostics private function
PHPUnit_Util_Log_TAP::writeNotOk protected function
PHPUnit_Util_Log_TAP::__construct public function Constructor. Overrides PHPUnit_Util_Printer::__construct
PHPUnit_Util_Printer::$autoFlush protected property If true, flush output after every write.
PHPUnit_Util_Printer::$out protected property
PHPUnit_Util_Printer::$outTarget protected property
PHPUnit_Util_Printer::$printsHTML protected property 1
PHPUnit_Util_Printer::flush public function Flush buffer, optionally tidy up HTML, and close output if it's not to a php stream 2
PHPUnit_Util_Printer::getAutoFlush public function Check auto-flush mode.
PHPUnit_Util_Printer::incrementalFlush public function Performs a safe, incremental flush.
PHPUnit_Util_Printer::setAutoFlush public function Set auto-flushing mode.
PHPUnit_Util_Printer::write public function 1