简体   繁体   English

Kohana 3和SimpleTest使用autorun.php

[英]Kohana 3 and SimpleTest using autorun.php

How do I go about integrating Simpletest with Kohana 3? 如何将Simpletest与Kohana 3集成在一起? I have checked out this answer but I like to use the autorun.php functionality from SimpleTest. 我已经签出了这个答案,但是我想使用SimpleTest的autorun.php功能。

After some hours of looking over the code, I have discovered how to do it 经过几个小时的检查,我发现了如何做

  1. Create a new copy of index.php, and name it test_index.php 创建index.php的新副本,并将其命名为test_index.php
  2. disable the error_reporting line in test_index.php 禁用test_index.php中的error_reporting行
  3. Create a new copy of bootstrap.php, and name it test_bootstrap.php 创建bootstrap.php的新副本,并将其命名为test_bootstrap.php
  4. comment out the request at the bottom 在底部注释掉请求
  5. Ensure that test_index.php includes test_boostrap.php instead of bootstrap.php 确保test_index.php包含test_boostrap.php而不是bootstrap.php
  6. Add simpletests to the directory structure 向目录结构添加simpletests
  7. Write the test case - include 'test_index.php' and 'autorun.php' (from simpletests) and code test cases as usual. 编写测试用例-像往常一样包括“ test_index.php”和“ autorun.php”(来自simpletests)并编写代码测试用例。

My example: 我的例子:

<?php
include_once ("../../test_index.php");
include_once ("../simpletest/autorun.php");

class kohana_init_test extends UnitTestCase
{
    function testTrue()
    {
        $this->assertTrue(true);
    }

    function testWelcome()
    {
        $response = Request::factory('main/index')->execute()->response;

        $this->assertEqual($response->content, 'testing');

    }
}

?>

Some notes: the $response variable depends on if you are using a View or pure text output. 一些注意事项:$ response变量取决于您使用的是View还是纯文本输出。 If you are using the template controller or a view, then $response is the view which you have used to render the content. 如果使用模板控制器或视图,则$ response是用于呈现内容的视图。 Variables in the view are avaliable , as shown above (the variable content is defined inside the view). 视图中的变量可用,如上所示(变量内容在视图内部定义)。

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

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