ZF + Doctrine2 phpUnit 错误:PDOExeption:您无法序列化或反序列化 PDO 实例

2023-12-24

我正在使用 DynamicGuys Doctrine2 集成到 zend 框架中(https://github.com/dynamicguy/zf1doctrine2)。 它有效,但如果我想用 phpUnit 进行测试,我会收到此错误: PDOExeption:您无法序列化或反序列化 PDO 实例

我搜索了一下,发现如果我注释掉这个文件中的第 44 行:https://github.com/dynamicguy/zf1doctrine2/blob/master/library/ZendX/Doctrine2/Application/Resource/Entitymanagerfactory.php https://github.com/dynamicguy/zf1doctrine2/blob/master/library/ZendX/Doctrine2/Application/Resource/Entitymanagerfactory.phpphpUnit 可以工作,但是应用程序的其余部分当然不会工作,因为实体管理器不会被返回

关于错误从何而来的任何想法?


这与 PHPUnit 在每次测试之间备份全局变量和静态属性有关。如果您有一个 PDO 实例,它在尝试序列化时会崩溃。我遇到了类似的问题,我找不到 PDO 实例作为全局参数存储的位置,但在所需的测试中禁用 backupGlobals 和 backupStaticAttributes 为我解决了问题。

/**
 * Search test.
 *
 * @backupGlobals disabled
 * @backupStaticAttributes disabled
 *
 * @author Steven Rosato
 */
class SearchControllerTest extends \Majisti\Test\TestCase
{
    ...
}

source: http://sebastian-bergmann.de/archives/797-Global-Variables-and-PHPUnit.html http://sebastian-bergmann.de/archives/797-Global-Variables-and-PHPUnit.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ZF + Doctrine2 phpUnit 错误:PDOExeption:您无法序列化或反序列化 PDO 实例 的相关文章

随机推荐