Re: PHPUnit with OutputTestCase

From: Date: Sun, 08 Jul 2007 17:42:34 +0000
Subject: Re: PHPUnit with OutputTestCase
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47274@lists.php.net to get a copy of this message
On my invistigation, I've added a bit of code to verify an idea .
        $html = file_get_contents($this->tpldir . DIRECTORY_SEPARATOR . 'general.tpl');
        $html = str_replace(array('{config_file}', '{script_filename}'),
            array($conf_file, $_SERVER['SCRIPT_FILENAME']), $html);
        file_put_contents($this->tpldir . DIRECTORY_SEPARATOR . 'general.exp', $html);
$cc_exp = count_chars($html, 1); $_1 = var_export($cc_exp, true); file_put_contents($this->tpldir . DIRECTORY_SEPARATOR . 'count_chars.exp', $_1);
        $this->expectOutputString($html);
        $pearInfo->show();
        $now = ob_get_contents();
$cc_out = count_chars($now, 1); $_2 = var_export($cc_out, true); file_put_contents($this->tpldir . DIRECTORY_SEPARATOR . 'count_chars.out', $_2); AND I compare diff between count_chars on general.exp (expected result) and count_chars on general.out (actual output by ob_get_contents). My error was to compare results of re-write content (by file_put_contents). Of course the both file are binary equivalent due to rewrite in a Windows (my platform) format. BUT source are not equivalent : that is why --> PHPUnit\Framework\Constraint\IsEqual.php:220
                 return ($a == $b);
returns FALSE. And PHP has right ! To back to count_chars diff I found that count_chars.out : array ( 10 => 55, 13 => 32, ... // all other is same count_chars.exp : array ( 10 => 55, 13 => ?, // No entry if general.tpl is save on *nix format , and 13 => 55 if general.tpl is save on windows format ... // all other is same But WHY ob_get_contents give only 32 CR while there are 55 LF ? Any idea ? Laurent Laville a écrit :
Laurent Laville a écrit :
Laurent Laville a écrit :
Hi PHPUnit testers, I want to know if someone has already used the OutputTestCase extension to check if a full html page is equal to an expected result. I would like to use it to PEAR_Info Test Suite, but i'm not sure if it's the best solution, and also if there is not a problem with long content. While I try the guide example [1], all work fine with PHPUnit 3.1.2, but when I used it with a long content , I always a failure while I pretty sure to have both content (expected, and printed) equals. Feedback are welcome Laurent [1] http://www.phpunit.de/pocket_guide/3.1/en/testcase-extensions.html#testcase-extensions.output
Well, I suspect a new bug with PHPUnit 3.1.2
Finally I found the problem, with xdebug, and traces ! Under some condition it work good, but if you want to compare a full html page then you reach : --> PHPUnit\Framework\Constraint\IsEqual.php:220
                return ($a == $b);
That return FALSE with $a = expected html result, and $b = actual html output (return by ob_get_contents) To verify my idea, I've wrote a little script : <?php $exp = file_get_contents('c:\php\pear\pear_info\tests\templates\general.exp'); $out = file_get_contents('c:\php\pear\pear_info\tests\templates\general.out'); if ($exp == $out) { print "test 1. equal"; } else { print "test 1. diff"; } print "<br/>\n"; if (strip_tags($exp) == strip_tags($out)) { print "test 2. equal"; } else { print "test 2. diff"; } ?> Where $exp is the html output expected and $out the real result (ob_get_contents) And the results are ... tada !!! test 1. diff test 2. equal While a diff between 2 files tell me that there are binary equivalent. Any idea how to fix this problem ? With : Script used to see the problem in action [1], with template [2] that produce general.exp (line 138) and general.out (line 144) Laurent [1] http://cvs.php.net/viewvc.cgi/pear/PEAR_Info/tests/PEAR_Info_TestCase_Output.php?revision=1.1&content-type=text%2Fplain&pathrev=1.1 [2] http://cvs.php.net/viewvc.cgi/pear/PEAR_Info/tests/templates/general.tpl?view=log


« previous php.pear.dev (#47274) next »