PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Testing » PHPUnit » Bug #4342

Assign by reference bug in addListener

Details

Submitted2005-05-13 16:11 UTC
Fromd dot morgan at eris dot qinetiq dot com
StatusClosed
PackagePHPUnit
PHP Version4.3.11
OSWinXP
Roadmaps(Not assigned)

Comments

[2005-05-13 16:11 UTC] d dot morgan at eris dot qinetiq dot com

Description:
------------
PHPUnit version 1.2.2

When adding a test listener to PHPUnit_TestResult, the addListener method executes the code:

$this->_listeners[] = $listener;

which has the effect of adding a duplicate of the listener to the _listeners array instead of the listener passed.

To fix the bug, the line should read:

$this->_listeners[] =& $listener;

Reproduce code:
---------------
<?php
require_once("PHPUnit.php");

class MyTestListener extends PHPUnit_TestListener
{
var $suite;
var $results;
var $text;

function MyTestListener($new_suite)
{
$this->suite = $new_suite;
$this->results =& new PHPUnit_TestResult();
$this->results->addListener(&$this);

$this->text = "foo";
}

function run()
{
$this->suite->run($this->results);
echo $this->text;
}

function endTest(&$test)
{
$this->text = "bar";
}
}
?>

Expected result:
----------------
When the above class is constructed with a test suite and then has run called, the text "bar" should be echoed.

Actual result:
--------------
When the above class is constructed with a test suite and then has run called, the text "foo" is echoed.