ZF + Doctrine2 phpUnit error: PDOExeption: You cannot serialize or unserialize PDO instances

前提是你 提交于 2019-12-22 08:54:38

问题


I'm using DynamicGuys doctrine2 integration into zend framework(https://github.com/dynamicguy/zf1doctrine2). It works, but if i want to make tests with phpUnit i get this error: PDOExeption: You cannot serialize or unserialize PDO instances

I've searched a bit, and i found out that if i comment out line 44 in this file: https://github.com/dynamicguy/zf1doctrine2/blob/master/library/ZendX/Doctrine2/Application/Resource/Entitymanagerfactory.php phpUnit works, but of course the rest of the application wont work, as the entity manager wont be returned

Any ideas on where the error comes from?


回答1:


This has something to do with PHPUnit backuping globals and static attributes between each tests. If you have a PDO instance it will break up when trying to serialize. I ran into a similar issue and I could not find where the PDO instance was stored as a global parameter, but disabled the backupGlobals and backupStaticAttributes in the needed test did the trick for me.

/**
 * 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



来源:https://stackoverflow.com/questions/5234432/zf-doctrine2-phpunit-error-pdoexeption-you-cannot-serialize-or-unserialize-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!