Issues

ZF-9380: Redeclaration of PHPUnit_Test_Case

Issue Type: Bug Created: 2010-03-09T07:28:30.000+0000 Last Updated: 2012-03-12T14:15:35.000+0000 Status: Closed Fix version(s): Reporter: Erik Wegner (eman) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Test_PHPUnit

  • zf-caretaker-adamlundrigan

Related issues: Attachments: - ControllerTestCase_require.diff

Description

A simple

<pre class="highlight">
php -r "require_once 'PHPUnit/Framework/TestCase.php';"

produces the error

<pre class="highlight">
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.

Comments

Posted by Erik Wegner (eman) on 2010-03-09T07:29:45.000+0000

Patch attached

Posted by Thomas Bachmann (thobach) on 2010-03-20T09:54:45.000+0000

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

Posted by Thomas Bachmann (thobach) on 2010-03-21T08:09:08.000+0000

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

Posted by Erik Wegner (eman) on 2010-03-22T04:34:39.000+0000

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

<pre class="highlight">
require_once 'PHPUnit/Framework.php';

line?

Posted by Thomas Bachmann (thobach) on 2010-03-23T12:24:38.000+0000

When I follow one of these instructions: * http://blog.fedecarg.com/2008/12/… * http://zendcasts.com/unit-testing-with-the-zend-fr… I don't need any modification. I guess it is not well documented in the programmer's reference. But if you have a phpunit.xml and call phpunit via the command-line, it should work.

Posted by Erik Wegner (eman) on 2010-03-26T03:30:31.000+0000

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.

Posted by Thomas Bachmann (thobach) on 2010-03-27T07:37:23.000+0000

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.

Posted by Michelangelo van Dam (dragonbe) on 2010-07-15T13:20:17.000+0000

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)

Posted by Till Klampaeckel (till) on 2010-08-24T07:22:43.000+0000

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.

Posted by Erik Wegner (eman) on 2010-08-25T00:54:25.000+0000

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.

Posted by Andries Seutens (andries) on 2010-12-17T03:17:15.000+0000

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

Posted by Adam Lundrigan (adamlundrigan) on 2012-03-12T13:35:18.000+0000

I am unable to reproduce the issue against trunk using PHPUnit 3.4.15. I vote for closing as "Not an Issue"

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts