加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何在Kohana中实现SimpleTest

发布时间:2020-12-13 17:02:00 所属栏目:PHP教程 来源:网络整理
导读:我的老板指派我学习如何使用Kohana并实施简单的测试.我们希望将其用作未来项目的框架. 作为KohanaPHP和SimpleTest的新手,我无法弄清楚如何对我的助手进行最简单的测试.我甚至找不到关于如何将SimpleTest附加到Kohana的逐步教程. 这里有人有想法吗? 解决方法
我的老板指派我学习如何使用Kohana并实施简单的测试.我们希望将其用作未来项目的框架.

作为KohanaPHP和SimpleTest的新手,我无法弄清楚如何对我的助手进行最简单的测试.我甚至找不到关于如何将SimpleTest附加到Kohana的逐步教程.

这里有人有想法吗?

解决方法

我们在Kohana创建了一个SimpleTest_controller

它从目录测试中获得测试

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,-4 ) );
      }
    }

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读