Zend Framework 项目 PHPUnit 测试中的 sfYaml echoln() 错误
我正在启动一个 Zend Framework 项目,并决定使用 Doctrine 1.2.3 而不是 Zend_Db 类。我配置了我的项目和学说命令行脚本工作得很好,我的索引控制器可以毫无问题地查询我的数据库,但使用 PHPUnit 进行单元测试会抛出错误:
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
我正在使用带有 PHP 5.3 的 Zend Server。 PHPUnit 需要 PEAR SymfonyComponents 的 YAML 包。每当我的单元测试引导程序尝试重新创建和加载整个测试数据库时,特别是在加载装置文件时,都会发生这种情况。这是完整的命令和输出:
D:\Zend\Apache2\vhost\myproject\tests>phpunit
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded
PHPUnit 3.5.10 by Sebastian Bergmann.
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
D:\Zend\Apache2\vhost\myproject\tests>
结果,我的数据库已完全创建,并且数据装置已成功加载。但此错误会停止单元测试过程。我只有一个 Doctrine 模型的测试类,但即使我注释其测试代码,也会发生此错误。
这很奇怪,因为如果我手动执行教义脚本,它运行没有问题,并且当系统通过网络运行时不会发生错误。这仅发生在单元测试中。
如果 Doctrine 和 PHPUnit 都包含来自 PEAR 和 Doctrine 内部的相同 sfYaml 类,而不破坏工作系统,我如何避免这种库冲突?
I'm starting a Zend Framework project and I decided to use Doctrine 1.2.3 instead of the Zend_Db classes. I configured my project and doctrine command line script works just fine, my index controller can query my database without problems, but Unit Tests with PHPUnit throws an error:
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
I'm using Zend Server with PHP 5.3. PHPUnit requires the PEAR SymfonyComponents' YAML package. This happens everytime my unit test bootstrap tries to re-create and load the whole testing database, specially when loading the fixtures files. This is the full command and output:
D:\Zend\Apache2\vhost\myproject\tests>phpunit
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded
PHPUnit 3.5.10 by Sebastian Bergmann.
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
D:\Zend\Apache2\vhost\myproject\tests>
As result, my database is completely created and data fixtures are loaded successfully. But this error stops the Unit Testing process. I only have one test class for Doctrine models but this error happens even if I comment its testing code.
It is strange, because if I execute the doctrine script by hand, It runs without problems, and no error happens when the system runs via web. This just happens for Unit Testing.
How can I avoid this libraries collition, if both, Doctrine and PHPUnit include the same sfYaml class from PEAR and from inside Doctrine, without breaking the working system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在错误消息中看到 sfYaml.php 正在从两个不同的位置加载。您必须清理包含路径,以便它只有您需要的每个库的一份副本。在
bootstrap.php
中使用var_dump(get_include_path())
来诊断问题。You can see in the error message that sfYaml.php is being loaded from two different locations. You must clean up your include path so it has only one copy of each library you need. Use
var_dump(get_include_path())
in yourbootstrap.php
to diagnose the issue.