Location: PHPKode > projects > Rincewind > rincewind-2.6.4/tests/snaptest/core/reporter/reporters/tap.php
<?php

/**
 * Text Output Unit Test Reporter
 */
class Snap_Tap_UnitTestReporter extends Snap_UnitTestReporter implements Snap_UnitTestReporterInterface {

    protected $type_mapping = array(
        'pass'      => TRUE,
        'case'      => TRUE,
        'fail'      => FALSE,
        'skip'      => TRUE,
        'todo'      => FALSE,
        'defect'    => FALSE,
        'phperr'    => FALSE,
        'fatal'     => FALSE,
    );
    
    protected $phperr = 0;
    protected $report_counter = 1;
    
    public function generateHeader() {
        echo "\n";
        echo "TAP version 13\n";
        $this->flush();
    }
    
    public function announceTestCount($test_count) {
        echo "1..{$test_count}\n";
        $this->flush();
    }
    
    public function announceTestPass($report) {
        $this->displayReport($report);
    }
    public function announceTestFail($report) {
        $this->displayReport($report);
    }
    public function announceTestTodo($report) {
        $this->displayReport($report);
    }    
    public function announceTestSkip($report) {
        $this->displayReport($report);
    }
    public function announceTestDefect($report) {
        $this->displayReport($report);
    }
    public function announceTestCaseComplete($report) {
        $this->displayReport($report);
    }
    
    public function generateReport($reports) {}
    
    public function generateFooter() {
        // footer information
        echo "\n";
        echo "# Output generated by Snap TAP Output Reporter\n";

        
        if ($this->phperr > 0) {
            echo "\n";
            echo "# You have unchecked errors in your tests.  These errors should be\n";
            echo "# removed, or acknowledged with $this->willError() in their respective\n";
            echo "# tests.\n";
        }
        
        $addons = unserialize(SNAP_ADDONS);
        if (count($addons) > 0) {
            echo "\n";
            echo "# Addons Loaded:\n";
            foreach($addons as $addon) {
                echo '#    '.$addon['name']."\n";
            }
        }
        
        $this->flush();
    }
    
    protected function displayReport($report) {
        // skip case complete
        if ($report['type'] == 'case') {
            continue;
        }
        
        if ($report['type'] == 'debug') {
            $debug = str_replace(array("\r\n", "\r"), "\n", $report['message']);
            $debug = preg_replace('/\n/m', "\n# ", $debug);
            $file = $report['file'];
            echo "# DEBUG:\n# $file\n# $debug\n";
            continue;
        }
        
        if ($report['type'] == 'phperr') {
            $this->phperr++;
        }
        
        $report_number = $this->report_counter;
        $this->report_counter++;

        $function = (isset($report['function'])) ? $report['function'] : 'unknown';
        $classname = (isset($report['class'])) ? $report['class'] : 'unknown';
        $file = (isset($report['file'])) ? $report['file'] : 'unknown';
        $message = (isset($report['message'])) ? $report['message'] : 'unknown';
        
        // normalize pass status
        $pass_status = ($this->type_mapping[$report['type']]) ? 'ok' : 'not ok';
        
        // make pretty classname / function
        $pretty_function = preg_replace('/^test /i', '', preg_replace('/[^A-Z0-9 ]/i', '', preg_replace('/([A-Z])/', ' \\1', $function)));
        
        if ($report['type'] == 'skip') {
            echo "$pass_status $report_number - # SKIP $message\n";
        }
        elseif ($report['type'] == 'todo') {
            echo "$pass_status $report_number - # TODO $pretty_function\n";
        }
        else {
            echo "$pass_status $report_number - $pretty_function\n";
        }
        
        if (!$this->type_mapping[$report['type']]) {
            echo "  ---\n";
            echo "    message: $message\n";
            echo "    severity: fail\n";
            echo "    location:\n";
            echo "      method: $function\n";
            echo "      class:  $classname\n";
            echo "      file:   $file\n";
            echo "  ...\n";
        }
        
        $this->flush();
    }
    
    protected function flush() {
        if (!SNAP_CGI_MODE) {
            return;
        }
        
        @ob_flush();
        @flush();
    }
}
Return current item: Rincewind