Zend Framework

Redeclaration of PHPUnit_Test_Case

Details

Description

A simple

php -r "require_once 'PHPUnit/Framework/TestCase.php';"

produces the error

Fatal error: Cannot redeclare class PHPUnit_Framework_TestCase in C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php on line 116

The PHPUnit documentation says to include/require PHPUnit/Framework.php to write own derived test cases.

My application needs to load the Zend_Test_PHPUnit_ControllerTestCase class which uses the above require_once statement and therefore produced the error message about class redeclaration. When I replace the statement, my application and my very own tests run fine.

Activity

Hide
Erik Wegner added a comment -

Patch attached

Show
Erik Wegner added a comment - Patch attached
Hide
Thomas Bachmann added a comment -

I have the same problem with PHPUnit 3.4.11 and ZF 1.10.2 and PHP 5.3.

Show
Thomas Bachmann added a comment - I have the same problem with PHPUnit 3.4.11 and ZF 1.10.2 and PHP 5.3.
Hide
Thomas Bachmann added a comment -

When I apply the patch to /Zend/Test/PHPUnit/ControllerTestCase.php (remove the line with require_once('...TestCase.php')) I get the following error:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /usr/local/zend/share/ZendFramework/library/Zend/Test/PHPUnit/ControllerTestCase.php on line 54

Show
Thomas Bachmann added a comment - When I apply the patch to /Zend/Test/PHPUnit/ControllerTestCase.php (remove the line with require_once('...TestCase.php')) I get the following error: Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /usr/local/zend/share/ZendFramework/library/Zend/Test/PHPUnit/ControllerTestCase.php on line 54
Hide
Erik Wegner added a comment -

Did you just remove the line or did you replace it with the new

require_once 'PHPUnit/Framework.php';

line?

Show
Erik Wegner added a comment - Did you just remove the line or did you replace it with the new
require_once 'PHPUnit/Framework.php';
line?
Hide
Thomas Bachmann added a comment -

When I follow one of these instructions:

Show
Thomas Bachmann added a comment - When I follow one of these instructions:
Hide
Erik Wegner added a comment -

Thanks for your links to further explanations of setting up testing environments. But I'm am not running tests, instead I wanted to reuse a function from one of my tests, so I instantiated the test class and stumbled over the redeclaration error.

When running my tests (without applied patch), everything works fine. Instantiating the test class within the application in normal operation mode needs the modified require statement.

Show
Erik Wegner added a comment - Thanks for your links to further explanations of setting up testing environments. But I'm am not running tests, instead I wanted to reuse a function from one of my tests, so I instantiated the test class and stumbled over the redeclaration error. When running my tests (without applied patch), everything works fine. Instantiating the test class within the application in normal operation mode needs the modified require statement.
Hide
Thomas Bachmann added a comment -

Right, I had the same problem when I tried to execute my unit tests within my application and not via the phpunit command line interface. Therefore I prefer applying your patch in order to execute unit tests within let's say a regular controller (TestController.php) and access the returned unit test results from the website/ within the application.

Show
Thomas Bachmann added a comment - Right, I had the same problem when I tried to execute my unit tests within my application and not via the phpunit command line interface. Therefore I prefer applying your patch in order to execute unit tests within let's say a regular controller (TestController.php) and access the returned unit test results from the website/ within the application.
Hide
Michelangelo van Dam added a comment -

I had this issue also when I had a server that included the whole Zend Framework library in it's include path, while the ZF application had the ZF library in it's own "libary" folder.

Non the less, I don't consider it an issue since I cannot reproduce it. The patch file won't do any good, since require_once won't load it twice, unless you have two instances of the whole framework running.
Besides, with my test setup using only PHPUnit/Framework breaks my unit tests since I rely too much on those TestCases (e.g. integration testing)

Show
Michelangelo van Dam added a comment - I had this issue also when I had a server that included the whole Zend Framework library in it's include path, while the ZF application had the ZF library in it's own "libary" folder. Non the less, I don't consider it an issue since I cannot reproduce it. The patch file won't do any good, since require_once won't load it twice, unless you have two instances of the whole framework running. Besides, with my test setup using only PHPUnit/Framework breaks my unit tests since I rely too much on those TestCases (e.g. integration testing)
Hide
Till Klampaeckel added a comment -

I can't reproduce this either with 10.2 and the same phpunit version.

It sounds like it's a "bug" somewhere else? Maybe you mixed include/require with include_once/require_once.

I usually suggest to strip all of those statements from the library code and use an autoloader instead. Maybe that's why I'm not seeing any of it period.

Show
Till Klampaeckel added a comment - I can't reproduce this either with 10.2 and the same phpunit version. It sounds like it's a "bug" somewhere else? Maybe you mixed include/require with include_once/require_once. I usually suggest to strip all of those statements from the library code and use an autoloader instead. Maybe that's why I'm not seeing any of it period.
Hide
Erik Wegner added a comment -

Sorry, I cannot help any further on this issue, because I am no longer working at that system that produced the error.

If you wish so, you can close this issue. Thanks for your patience.

Show
Erik Wegner added a comment - Sorry, I cannot help any further on this issue, because I am no longer working at that system that produced the error. If you wish so, you can close this issue. Thanks for your patience.
Hide
Andries Seutens added a comment -

This issue should be fixed, could you please verify so we can close this issue?

Show
Andries Seutens added a comment - This issue should be fixed, could you please verify so we can close this issue?

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated: