views:

249

answers:

1

How 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.

A: 

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).

Extrakun