|
From: Adonis El F. <ad...@ay...> - 2012-12-19 21:06:13
|
Hi,
I am trying to do something a little different than usual with simpletest.
I am embedding tests in existing code that is used on a web environment, and most of our code is procedural so at certain checkpoints we execute the tests.
Our code already outputs text that goes to the web interface, and what we would like to do is have the simpletest reports be sent to a file, that we can open from a different interface and if it is xml, can be fed to an xUnit parser. Right now when we execute the tests, the output is clearly seen in the web page, so we are looking for a way to make the simpletest report message go to a file or a variable.
Right now I call the code simply like this
$test = new test_smarty_punto_display_menu($punto_object,$params,$time_start,$time_end);
$test->run(new HtmlReporter());
where the class file has this
require_once(dirname(__FILE__) . '/simpletest/unit_tester.php');
require_once(dirname(__FILE__) . '/simpletest/reporter.php');
class test_smarty_punto_display_menu extends UnitTestCase
{
var $punto_object; // pass the punto_object to do some sanity tests on it
var $params; //pass the params coming in to see if they are complete
var $time_start;
var $time_end;
function test_smarty_punto_display_menu($punto_object,$params,$time_start,$time_end) {
$this->punto_object = $punto_object;
$this->params = $params;
$this->time_start=$time_start;
$this->time_end=$time_end;
}
function setUp() { }
function testIfPuntoObjectNotNull()
{
$this->assertNotNull($this->punto_object);
}
function testIfParamsDebugIsFalse()
{
$params = $this->params;
$this->assertFalse($params['debug']);
}
function testIfParamsLocaleIsTrue()
{
$params = $this->params;
$this->assertTrue($params['locale']);
}
function testIfExecTimeIsLessThanHalfASecond()
{
$value = $this->time_end - $this->time_start ;
$this->assertTrue($value < 0.5);
}
function testIfParamsLayoutIsVerticalOrHorizontal()
{
if ( $this->params['layout'] == 'vertical' || $this->params['layout'] == 'horizontal' ) {
$is_valid = TRUE;
} else {
$is_valid = FALSE;
}
$this->assertTrue($is_valid);
}
function tearDown() { }
}
Since our code is already called from web, and it has output, I would like to get the reporter send it to a log file.
I have poked around in code, documentation and web searches and no luck in finding hints on how to do this. Is it possible? How can I run the test and be able to direct the output to a variable to be printed or saved to a log file. It would be awesome if I can still use the three report styles text, html and xml so we can use the output format that is best for the occasion.
Please note that I can not run the code on command line. Any help would be GREATLY appreciated!
Adonis
|