2011-03-31 11:03

# 从Zend Studio 8运行phpUnit测试套件时出现奇怪的错误

Zend Studio 8 has phpUnit integration and a dedicated view, which is great, so I would like to use it... but:

When I run my phpunit.xml on the command line, the tests are executed just fine, when I try to run phpunit.xml in Zend Studio as unit test, I get the following fatal error:

Fatal error: Uncaught exception 'PHPUnit_Framework_Error' with message 'Assigning the return value of new by reference is deprecated' in C:\Program Files (x86)\Zend\ZendServer\bin\PEAR\PEAR\Config.php:650

Stack trace:

#0 C:\Program Files (x86)\Zend\ZendServer\bin\PEAR\PEAR\RunTest.php(22): ZendPHPUnitErrorHandler->handle(8192, 'Assigning the r...', 'C:\Program File...', 650, Array)
#1 C:\Program Files (x86)\Zend\ZendServer\bin\PEAR\PEAR\RunTest.php(22): require_once()
#2 C:\Program Files (x86)\Zend\ZendServer\bin\PEAR\PHPUnit\Extensions\PhptTestCase.php(49): require_once('C:\Program File...')
#3 C:\Program Files (x86)\Zend\Zend Studio - 8.0.0\plugins\com.zend.php.phpunit_8.0.0.v20101001-0100esources\ZendPHPUnit.php(103): require_once('C:\Program File...')
#4 {main} thrown in C:\Program Files (x86)\Zend\ZendServer\bin\PEAR\PEAR\Config.php on line 650

I really don't have a clue what that means... why should some deprecated code in the PEAR config keep my tests from running?

My colleague who has neither PEAR nor phpunit installed, can run unit tests from Zend Studio 8 just fine but he can't run any from the CLI. So it seems that Zend Studio not only integrates with phpUnit but comes bundled with a version of it. I wanted the newest version and that's why I installed PEAR and then via PEAR I installed phpUnit. As a consequence, the phpUnit library of Zend Studio was outdated and I had to replace the file 'ZendPHPUnit.php' in the Zend Studio plugin folder with a version of a Zend Forum user. This lead to correct inclusion of the phpUnit classes and the current problem. [/edit]

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享
• 邀请回答

#### 1条回答

• dongtuoleng8624 10年前

Line 650 in PEAR\Config.php does

``````\$this->_registry['default'] = &new PEAR_Registry(
\$this->configuration['default']['php_dir']
);
``````

This will raise an `E_DEPRECATED` message depending on whether you have enabled error_reporting to include that level. The error handlers of `PHPUnit` and `ZendPHPUnit` will convert those to `PHPUnit_Framework_Exceptions`.

Because PHP will raise `E_DEPRECATED` already at compile time, the only way to suppress these errors is in php.ini. My assumption is, that your PHPUnit you run from CLI is using a different php.ini than that your Zend Studio and in that php.ini the error level is not low enough to raise `E_DEPRECATED`.

If you can provide a reproducable example, we might be able to make more sense of it. In any case, try to update your PEAR installation to the latest version.

点赞 评论 复制链接分享