开发者

Kohana 3 and SimpleTest using autorun.php

Ho开发者_如何学JAVAw do I go about integrating Simpletest with Kohana 3? I have checked out this answer but I like to use the autorun.php functionality from SimpleTest.


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
  2. disable the error_reporting line in test_index.php
  3. Create a new copy of bootstrap.php, and name it 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
  6. Add simpletests to the directory structure
  7. Write the test case - include 'test_index.php' and 'autorun.php' (from simpletests) and code test cases as usual.

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. If you are using the template controller or a view, then $response is the view which you have used to render the content. Variables in the view are avaliable , as shown above (the variable content is defined inside the view).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜