【问题标题】:Kohana 3 and SimpleTest using autorun.phpKohana 3 和 SimpleTest 使用 autorun.php
【发布时间】:2010-01-22 07:15:41
【问题描述】:

如何将 Simpletest 与 Kohana 3 集成?我已经检查了这个answer,但我喜欢使用 SimpleTest 中的 autorun.php 功能。

【问题讨论】:

    标签: php unit-testing kohana


    【解决方案1】:

    在查看代码几个小时后,我发现了如何做到这一点

    1. 创建 index.php 的新副本,并将其命名为 test_index.php
    2. 在 test_index.php 中禁用 error_reporting 行
    3. 创建 bootstrap.php 的新副本,并将其命名为 test_bootstrap.php
    4. 注释掉底部的请求
    5. 确保 test_index.php 包含 test_boostrap.php 而不是 bootstrap.php
    6. 向目录结构添加简单测试
    7. 编写测试用例 - 包括“test_index.php”和“autorun.php”(来自 simpletests)并像往常一样编写测试用例。

    我的例子:

    <?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');
    
        }
    }
    
    ?>
    

    一些注意事项:$response 变量取决于您使用的是视图还是纯文本输出。如果您使用的是模板控制器或视图,那么 $response 就是您用来呈现内容的视图。视图中的变量可用,如上图(变量内容在视图内部定义)。

    【讨论】:

      猜你喜欢
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      • 2013-05-02
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多