Home » Testing » PHPUnit » Bug #4342
Assign by reference bug in addListener
Details
| Submitted | 2005-05-13 16:11 UTC |
|---|---|
| From | d dot morgan at eris dot qinetiq dot com |
| Status | Closed |
| Package | PHPUnit |
| PHP Version | 4.3.11 |
| OS | WinXP |
| 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.