2

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Wrikken, thanks for your answer. I tried this out, but this doesn't help me. I also need to add that I don't have written a Autoload.php by myself.
In my unit test files there are the following includes: require_once "../classes/myClass.class.php"; require "PHPUnit/Autoload.php"; changing it to the following makes it work for some, but not all classes require_once "../classes/PropertySetField.class.php"; require_once "PHPUnit/Autoload.php";
Drop that last require: it is already included in C:\Program Files (x86)\PHP\v5.3\phpunit, so dropping the line require "PHPUnit/Autoload.php should work. (And: always use _once for class / function includes & requires).
Thanks for your help, Wrikken. (I always used require_once, except for these Autoload-lines in my unit tests)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.