PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Testing » PHPUnit » Bug #2875

example from PHPUnit.php does not work

Details

Submitted2004-12-02 16:09 UTC
Fromchristian at wenz dot org
StatusBogus
PackagePHPUnit
PHP Version4.3.10RC1
OSWinXP
Roadmaps(Not assigned)

Comments

[2004-12-02 16:09 UTC] christian at wenz dot org

Description:
------------
I just played around with PHPUnit and PHP 4.3.10RC1 (usually I am using PHPUnit2) and stumbled upon this:

The MathTest code from PHPUnit.php (v1.13) returns the following error:

Fatal error: Call to a member function on a non-object in /path/to/pear/PHPUnit/TestResult.php on line 276

To fix, change TestResult.php

Lines 275-276. Old:
get_class($passedTest),
$passedTest->getName()
New:
get_class($passedTest[0]),
$passedTest[0]->getName()

Line 281. Old:
$result .= $failedTest->toString();
New:
$result .= $failedTest[0]->toString();

But maybe something else triggered this?!

Reproduce code:
---------------
<?php
require_once 'PHPUnit.php';

class MathTest extends PHPUnit_TestCase {
var $fValue1;
var $fValue2;

function MathTest($name) {
$this->PHPUnit_TestCase($name);
}

function setUp() {
$this->fValue1 = 2;
$this->fValue2 = 3;
}

function testAdd() {
$this->assertTrue($this->fValue1 + $this->fValue2 == 5);
}
}

$suite = new PHPUnit_TestSuite();
$suite->addTest(new MathTest('testAdd'));

$result = PHPUnit::run($suite);
print $result->toHTML();
?>

Expected result:
----------------
TestCase mathtest->testAdd() passed

Actual result:
--------------
Fatal error: Call to a member function on a non-object in /path/to/pear/PHPUnit/TestResult.php on line 276

[2004-12-02 16:44 UTC] christian at wenz dot org

oh no ... with 4.3.9, it works as expected. So this is most certainly a bug with PHP 4.3.10RC1. Maybe anyone who knows the internals of PHPUnit1 better than I do can find out easily what the real issue is (and file a PHP bug report)?