views:

443

answers:

3

Before installing PHPUnit on my Ubuntu machine, I thought I had zf.sh all set up correctly. I was able to create a new project without any issues. Now, since installing PHPUnit, everything is not working right.

When I try to create a test project, I get this:

Fatal error: Cannot redeclare class PHPUnit_Framework_TestSuite_DataProvider in /usr/share/php/PHPUnit/Framework/TestSuite/DataProvider.php on line 64

Call Stack:
0.0011     110200   1. {main}() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/bin/zf.php:0
0.0011     110320   2. zf_main() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/bin/zf.php:23
0.0113     685448   3. zf_run() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/bin/zf.php:36
0.0113     685568   4. Zend_Tool_Framework_Client_Console::main() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/bin/zf.php:214
0.0114     686044   5. Zend_Tool_Framework_Client_Abstract->dispatch() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/library/Zend/Tool/Framework/Client/Console.php:96
0.0114     686164   6. Zend_Tool_Framework_Client_Abstract->initialize() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/library/Zend/Tool/Framework/Client/Abstract.php:209
0.0152     866128   7. Zend_Tool_Framework_Loader_Abstract->load() /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/library/Zend/Tool/Framework/Client/Abstract.php:118
0.4374    2729116   8. include_once('/usr/share/php/PHPUnit/Framework/TestSuite/DataProvider.php') /opt/ZendFramework/ZendFramework-1.9.3PL1-minimal/library/Zend/Tool/Framework/Loader/Abstract.php:90

What do I need to do to get it working again?

Update: I think I understand the reason why this is happening. In PHPUnit 3.4.0 there is a class with the same name as the Zend Framework 1.9.3. Apparently it is a known issue. But how can I get around this so I can use Zend_Tool again?? Can I downgrade PHPUnit? Will that fix the problem?

Update: This tutorial mentions something about installing a diff patch.

+3  A: 

I found a temporary workaround:

  • Edit PHPUnit/Framework.php, near line 70:

    require 'PHPUnit/Framework/TestSuite/DataProvider.php';
    
  • Change to:

    require_once 'PHPUnit/Framework/TestSuite/DataProvider.php';
    

This is probably not the long-term fix, but it resolves the immediate symptom.


Update 2009-11-20: I just saw a commit to the ZF 1.9 branch that claims to resolve this issue. Presumably the fix will be in the next point-release (1.9.6) and in subsequent minor releases (1.10.0 and later).

Bill Karwin
cool, thanks! much easier to understand the problem. nice explanation.
Andrew
A: 

Another solution, which doesn't require to change any 3th party code, is copying the PHPUnit folder to a location outside the include_path and create a symlink to the new location instead.

For details on this issue have a look here: Zend_Tool troubles PHPUnit

A: 

Another solution described in this blog post

Andy