PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Dec 11, 2018 11:12 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Mon Aug 17, 2009 7:17 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
hi guys,..
iam very new with simpletest frame work and i tried some small testing app,...but my question is: could i create a separate HTML file which view the results of testing.(i.e i want a file say testResult.html which contains the result of test).


thanks for advance


Top
 Profile  
 
PostPosted: Wed Aug 19, 2009 8:44 am 
Offline
Forum Commoner
User avatar

Joined: Tue Aug 18, 2009 12:39 am
Posts: 58
Location: Chennai city, India
Hello ,
I hope this code will satisfy your needs. Try this code, if it's OK means u can use it. Don't forget to see note below the code.

Syntax: [ Download ] [ Hide ]
<?php
$testresult = "hello world!";
 
$testresult = addslashes($testresult);
 
$fileoutput = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Testing Result</title>
</head>
 
<body>
$testresult
</body>
</html>"
;
 
$filename = "test_".rand(1,10000).".html";
 
$fp = fopen($filename, 'w');
fwrite($fp, $fileoutput);
fclose($fp);
 
 
?>


Note: Input your output (Result to print on html file) on ' $testresult ' and file name will auto generated with starting prefix 'test_' followed with random number.


Top
 Profile  
 
PostPosted: Wed Aug 19, 2009 10:07 pm 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
The result of an individual assertion or a whole suite of tests? Because if you're after the latter and you're currently running the tests from the shell you could just redirect the output:
Syntax: [ Download ] [ Hide ]
./run_tests > test_results.txt
It's not HTML of course but you could hack SimpleTest to produce HTML from the shell (or CLI in PHP terminology) fairly easily.


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 4:46 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
sorry for distribution,..

but i have a simple question...where is the simpletest APIs and functions as $test->run(new HtmlReporter()); or something like that...that i have to use to produce the result...?


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 7:45 am 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
Line 125 of simpletest/test_case.php on my version, which is a bit old now.


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 7:47 am 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
If you are hacking SimpleTest best thing you could do, design wise, would be to write a SaveAsFileReporter. You can see the existing reporter implementations in simpletest/reporter.php. Without looking too closely you'll probably want to start by subclassing SimpleReporter. Ah, it's all so "Simple" in SimpleTest :-)


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 8:22 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
thanks Ollie Saunders for ur concern with my post

may be it is simple from ur point of view ..but i still newbie to this concept of testing at all ,so if u have any type of helpful links or guides i'll be more than thankful...

thanks


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 8:49 am 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
That's fine. What are you using SimpleTest for, out of interest?


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 8:54 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
i just begin with the tutorial on simpletest main site and i made it succesfully ,but all what i need now is to make output of the testing to be written in text file instead of running as TextReporter() or HtmlReporter()...that is all


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 8:57 am 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
Thinking about it, this is probably your simplest way:
Syntax: [ Download ] [ Hide ]
ob_start();
$test->run(new HtmlReporter);
$testOutput = ob_get_contents();
ob_end_clean();
file_put_contents($fileName, $testOutput);


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 9:11 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
really iam soo greatful for u :oops:

do u mean that my test case will be some thing like that...


Syntax: [ Download ] [ Hide ]
 
<?
    require_once('plugins\unit_tester.php');
    require_once('plugins\reporter.php');
   
 
 
    $test = &new GroupTest('All tests');
    $test->addTestFile('string_tests.php');
    $test->addTestFile('array_tests.php');
 
   
    ob_start();
        $test->run(new HtmlReporter);
        $testOutput = ob_get_contents();
        ob_end_clean();
        $f = "logs/testlog.txt";
        file_put_contents($f, $testOutput);
 
   
?>
 


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 9:14 am 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
Try it!


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 9:15 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
yes ...i did ...but the file that i spacify to write output in still empty.... :roll:


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 9:22 am 
Offline
DevNet Master
User avatar

Joined: Tue May 24, 2005 6:01 pm
Posts: 3179
Location: UK
If you comment out all the ob_* stuff do you get any output?
Otherwise, did you create the file manually first?


Top
 Profile  
 
PostPosted: Thu Aug 20, 2009 9:30 am 
Offline
Forum Newbie

Joined: Sun Aug 16, 2009 7:59 am
Posts: 16
Ollie Saunders ur genius .... :wink:

it works perfect now ...thanks alot


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group