How to implement SimpleTest in Kohana

蹲街弑〆低调 提交于 2019-12-05 01:52:06

问题


My boss assigned me to learn how to use Kohana and implement simple test in that. We would like to use it as our framework for future projects.

Being new to both KohanaPHP and SimpleTest, I can't figure out how to do even the simplest test of my helpers. I can't even find a single step-by-step tutorial on how to attach SimpleTest to Kohana.

Anyone here have an idea?


回答1:


We've created a SimpleTest_controller in Kohana

and it gets the test from a directory tests

define ( 'SIMPLE_TEST', '../tools/simpletest/');
require_once(SIMPLE_TEST . 'unit_tester.php');
require_once(SIMPLE_TEST . 'reporter.php');
require_once( SIMPLE_TEST . 'mock_objects.php');

class SimpleTest_Controller extends Controller {
  function index() {
    $this->runall();
  }

  function runall() {
    $sDir = '../tests/';
    $rDir = opendir( $sDir );

    while ( $sFile = readdir( $rDir ) ) {
      if ( $sFile != '.' && $sFile != '..' ) {
        $this->run( $sFile );
      }
    }
  }

  function run ( $sTests ) {
    $sDir = '../tests/' . $sTests .'/';
    $rDir = opendir( $sDir );
    $test = new GroupTest( $sTests );

    while ( $sFile = readdir( $rDir ) ) {
      if ( $sFile != '.' && $sFile != '..' && !preg_match('/~\d+~/', $sFile) ) {
        include_once($sDir . $sFile);
        $test->addTestCase( substr($sFile, 0, -4 ) );
      }
    }

    $test->run( new HtmlReporter() );
  }
}

you can call domain.com/simpletest to run all or you can call domain.com/simpletest/run/account if you have a accountfolder in your testfolder



来源:https://stackoverflow.com/questions/1665835/how-to-implement-simpletest-in-kohana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!