简体   繁体   中英

Cannot redeclare phpunit_autoload when running unit tests in Netbeans

More than a year ago I installed PHP via the Microsoft Web Platform Installer. The installed version of PHP is 5.3.6. Then I installed PPHUnit through PEAR (version 3.5.14). I used it to run my unit tests via Netbeans, which was running fine till I upgraded PHPUnit to the latest version (3.6.11). Since that time I can't run my unit tests anymore.

When I look to the PHPUnit-configuration in the Netbeans options no errors are reported and phpunit.bat is recognized well. This is the content of phpunit.bat:

set PHPBIN="C:\Program Files (x86)\PHP\v5.3\php.exe"
%PHPBIN% "C:\Program Files (x86)\PHP\v5.3\phpunit" %*

But when I try to run the unit tests I get the following errors in the Output window of Netbeans:

Fatal error: Cannot redeclare phpunit_autoload() (previously declared in C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Autoload.php:51) in C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Autoload.php on line 205
---
Call Stack:
    0.0003     323984   1. {main}() C:\Program Files (x86)\PHP\v5.3\phpunit:0
    0.0055     731680   2. PHPUnit_TextUI_Command::main() C:\Program Files (x86)\PHP\v5.3\phpunit:46
    0.0055     732096   3. PHPUnit_TextUI_Command->run() C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\TextUI\Command.php:130
    0.0420    1218480   4. PHPUnit_Runner_BaseTestRunner->getTest() C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\TextUI\Command.php:150
    0.0877    1596168   5. ReflectionMethod->invoke() C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Runner\BaseTestRunner.php:124
    0.0877    1596184   6. NetBeansSuite::suite() C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Runner\BaseTestRunner.php:124
    0.0893    1600944   7. PHPUnit_Framework_TestSuite->addTestFile() D:\Program Files\NetBeans 7.1\php\phpunit\NetBeansSuite.php:85
    0.0893    1601408   8. PHPUnit_Util_Fileloader::checkAndLoad() C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Framework\TestSuite.php:358
    0.0898    1601504   9. PHPUnit_Util_Fileloader::load() C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Util\Fileloader.php:79
    0.1028    1633840  10. include_once('D:\Inetpub\wwwroot\DTS\unit\UploadException.test.php') C:\Program Files (x86)\PHP\v5.3\PEAR\PHPUnit\Util\Fileloader.php:95

Dump $_GET


Since this problem appeared I have uninstalled and reinstalled several times PHPUnit, but it didn't improve the situation. Pear itself is also upgraded to the latest version (1.9.4).

Does anybody has an idea how to get rid of these errors?

For some reason, it thinks it needs to reload Autoload.php . You can try to alter the require on line 203 to require_once to see it that helps. If I hazard a guess, it is because your own codes autoloader wants to load something similarily named, and it conflicts with the autoloader in PHPUnit itself. Perhaps namespacing the classes, or making sure you autoloader is loaded before PHPUnit's, might do the trick. I would consider it a bug though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM