Created
July 16, 2011 13:33
-
-
Save yuya-matsushima/1086363 to your computer and use it in GitHub Desktop.
MY_Unit_test.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class MY_Unit_test extends CI_Unit_test | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function report($result = array()) | |
{ | |
if(count($result) == 0) | |
{ | |
$result = $this->result(); | |
} | |
$CI = get_instance(); | |
$CI->load->language('unit_test'); | |
$this->_parse_template(); | |
$r = ''; | |
if( ! defined('STDIN')) | |
{ | |
foreach($result as $res) | |
{ | |
$table = ''; | |
foreach($res as $key=>$val) | |
{ | |
if($key == $CI->lang->line('ut_result')) | |
{ | |
if($val == $CI->lang->line('ut_passed')) | |
{ | |
$val = '<span style="color: #0C0;">' . $val . '</span>'; | |
} | |
elseif($val == $CI->lang->line('ut_failed')) | |
{ | |
$val = '<span style="color: #C00;">' . $val . '</span>'; | |
} | |
} | |
$tmp = $this->_template_rows; | |
$tmp = str_replace('{item}', $key, $tmp); | |
$tmp = str_replace('{result}', $val, $tmp); | |
$table .= $tmp; | |
} | |
$r .= str_replace('{rows}', $table, $this->_template); | |
} | |
return $r; | |
} | |
else | |
{ | |
$passed = 0; | |
$failed = 0; | |
$count = 0; | |
$failed_test = array(); | |
$r1 = "Execute Unit Test!! \n\n"; | |
foreach($result as $res) | |
{ | |
if($res['Result'] == 'Passed') | |
{ | |
$passed += 1; | |
$count += 1; | |
} | |
elseif($res['Result'] == 'Failed') | |
{ | |
$failed += 1; | |
$count += 1; | |
$failed_test[] = preg_match('/^undefined/ui', $res['Test Name']) ? 'L' . $res['Line Number'] : $res['Test Name']; | |
} | |
} | |
$r2 = sprintf("Total:%s Passed:%s Failed:%s\n", $count, $passed, $failed); | |
if(count($failed_test) > 0) | |
{ | |
$r = $r1 . "\x1b[31m" . $r2 . "\x1b[0m" . sprintf("Failed: %s \n", implode(', ', $failed_test)); | |
} | |
else | |
{ | |
$r = $r1 . "\x1b[32m" . $r2 . "\x1b[0m"; | |
} | |
return $r; | |
} | |
} | |
} | |
/* End of file MY_Unit_test.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment