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
- Create a new copy of index.php, and name it test_index.php
- disable the error_reporting line in test_index.php
- Create a new copy of bootstrap.php, and name it test_bootstrap.php
- comment out the request at the bottom
- Ensure that test_index.php includes test_boostrap.php instead of bootstrap.php
- Add simpletests to the directory structure
- 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).
精彩评论