Home » Testing » PHPUnit2 » Bug #5720
Class 'PHPUnit2_Framework_TestCase' not found (Warning.php line 37)
Details
| Submitted | 2005-10-19 19:02 UTC |
|---|---|
| From | tom at tomhowells dot co dot uk |
| Assigned | sebastian |
| Status | Closed |
| Package | PHPUnit2 |
| PHP Version | 5.0.5 |
| OS | Windows XP |
| Roadmaps | (Not assigned) |
Comments
[2005-10-19 19:02 UTC] tom at tomhowells dot co dot uk
Description:
------------
I'm trying to execute a test suite through the PHP CLI, however it's reported that my PHP script contains a syntax error; when viewed through a browser, the following fatal error is given:
Fatal error: Class 'PHPUnit2_Framework_TestCase' not found in C:\PHP\PEAR\lib\PHPUnit2\Framework\Warning.php on line 37
I found a closed bug very similar to this one (#3402), and I suspect the cause is the same, as the error appears almost identical under the same type of conditions; I'm running PHPUnit2 2.3.0 under PHP 5.0.5 on Windows XP.
See below for the source of the PHP script generating this error.
Test script:
---------------
// all.php
<?php
require_once('PHPUnit2/Framework/TestCase.php');
require_once('PHPUnit2/Framework/TestSuite.php');
require_once('PHPUnit2/TextUI/TestRunner.php');
require_once('external.php');
$suite = new PHPUnit2_Framework_TestSuite;
$suite->addTestSuite('ExternalDataTest');
PHPUnit2_TextUI_TestRunner::run($suite);
?>
// external.php
<?php
require_once('../includes/errors.php');
require_once('../includes/external.php');
class ExtDataTest extends ExternalData {
public static function getData($key, &$array, $default, $type) {
return parent::getData(key, $array, $default, $type);
}
}
class ExternalDataTest extends PHPUnit2_Framework_TestCase {
public static function testGetData() {
static $array = array('one' => 'test', 'two' => ' testing ', 'three' => 'true', 'four' => ' 1 ', 'five' => 0, 'six' => array(1, 2, 3), 'seven' => '');
static $default = 'Nothing';
static $data_types = array('one' => 'string', 'two' => 'string', 'three' => 'boolean', 'four' => 'int', 'five' => 'boolean', 'six' => 'array', 'seven' => 'string');
static $expected = array('one' => 'test', 'two' => 'testing', 'three' => true, 'four' => 1, 'five' => false, 'six' => array(1, 2, 3), 'seven' => 'Nothing');
foreach ($array as $key => $value) {
$result = ExtDataTest::getData($key, $array, $default, $data_types[$key]);
self::assertTrue($result === $expected[$key], "External data for array element: $key\n Expected result: $expected[$key]\n Actual result: $result\n");
}
}
}
?>
Actual result:
--------------
Fatal error: Class 'PHPUnit2_Framework_TestCase' not found in C:\PHP\PEAR\lib\PHPUnit2\Framework\Warning.php on line 37
Call Stack
# Function Location
1 {main}() c:\Apache\htdocs\all.php:0
2 require_once() c:\Apache\htdocs\all.php:2
3 require_once() C:\PHP\PEAR\lib\PHPUnit2\Framework\TestCase.php:26
4 require_once() C:\PHP\PEAR\lib\PHPUnit2\Framework\TestResult.php:25
5 require_once() C:\PHP\PEAR\lib\PHPUnit2\Framework\TestListener.php:24
6 require_once() C:\PHP\PEAR\lib\PHPUnit2\Framework\TestSuite.php:26
[2005-10-19 20:33 UTC] mseo at fermatcapital dot com
Yes. I'm having the same fatal error. I found a circular
dependency of require_once's, and in the class TestCase is
caught chasing its tail. I believe this was the problem in
#3402. See below for the dependencies. Note that Test...is
short for PHPUnit2_Framework_Test... and Warning is actually
PHPUNit2_Framework_Warning.
TestCase-TestResult-TestListener-TestSuite-Warning-TestCase
The require_once's are circular in the other versions as
well (e.g. v2.2.0 and v2.1.5), but appearantly, the class
PHPUnit2_Framework_TestCase is not being circularly
referenced.
I'm running Entropy's distribution of PHP-5.0.4-1 on MacOSX
10.4.2
[2005-10-20 05:00 UTC] sebastian at php dot net
I added a workaround for this and released PHPUnit 2.3.1.
This issue will be properly fixed in PHPUnit 2.4, which will use the SPL Autoloader of PHP 5.1.0 to resolve the circular dependencies.