如何在Kohana中实现SimpleTest [英] How to implement SimpleTest in Kohana

查看:83
本文介绍了如何在Kohana中实现SimpleTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的老板指派我学习如何使用Kohana并在其中进行简单的测试.我们希望将其用作未来项目的框架.

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.

KohanaPHP SimpleTest ,我什至不知道该如何对助手进行最简单的测试.我什至找不到关于如何将SimpleTest附加到Kohana的单个分步教程.

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.

这里有人有主意吗?

推荐答案

我们已经在Kohana中创建了一个SimpleTest_controller

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() );
  }
}

您可以调用domain.com/simpletest运行所有 或者如果您的测试文件夹中有一个帐户文件夹,则可以致电domain.com/simpletest/run/account

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

这篇关于如何在Kohana中实现SimpleTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆