简体   繁体   English

如何在Kohana中实现SimpleTest

[英]How to implement SimpleTest in Kohana

My boss assigned me to learn how to use Kohana and implement simple test in that. 我的老板指派我学习如何使用Kohana并实施简单的测试。 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. 作为KohanaPHPSimpleTest的 新手 ,我无法弄清楚如何对我的助手进行最简单的测试。 I can't even find a single step-by-step tutorial on how to attach SimpleTest to Kohana. 我甚至找不到关于如何将SimpleTest附加到Kohana的逐步教程。

Anyone here have an idea? 这里有人有想法吗?

We've created a SimpleTest_controller in Kohana 我们在Kohana创建了一个SimpleTest_controller

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 您可以调用domain.com/simpletest来运行全部,或者如果您的testfolder中有一个帐户文件夹,则可以调用domain.com/simpletest/run/account

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM