Welcome Guest, Not a member yet? Register   Sign In
An idea for simple testing
#1

[eluser]Unknown[/eluser]
I want to share with you this controller I wrote in order to do very simple testing. It uses the "unit_test" library and php reflection.

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_TestController extends CI_Controller
{
    function __construct()
    {
        parent::__construct();        
        $this->load->library("unit_test");
    }
    
    public function index()
    {
        $class_methods = get_class_methods($this);
        
        foreach ($class_methods as $method_name)
        {    
            if (preg_match("/".preg_quote("_test") .'$/', $method_name))
            {            
                $method = new ReflectionMethod($this, $method_name);
                $method->invoke($this);
            }        
        }
        
        echo $this->unit->report();
    }
}
?>

To use this controller you have to include it:

Code:
require_once(APPPATH."/core/MY_TestController.php");

each test you want to run has to be in a function. The name of the function has to end with "_test". Other function are ignored and can be used for other stuff.

I hope this will be useful.




Theme © iAndrew 2016 - Forum software by © MyBB