Search code examples
zend-frameworkphpunitdoctrine-ormzend-test

PHPUnit/Zend_Test: PDOException: You cannot serialize or unserialize PDO instances


I am getting the exception

PDOException: You cannot serialize or unserialize PDO instances

when I am trying to use PHPUnit for Unit Tests. I have not much going on. I am using Zend Framework 1.11. I guess it maybe that I have Bootstrapped my application storing the entity manager in Zend_Registry?

// application/Bootstrap.php -> _initDoctrine()
$em = EntityManager::create($doctrineOptions['connectionOptions'], $config);
Zend_Registry::set("em", $em);

For my unit test, it looks like

class Application_Models_UserTest extends Zend_Test_PHPUnit_ControllerTestCase
  public function testUnitTest() {
    $this->assertTrue(true);
  }
}

My phpunit.xml looks like http://pastebin.com/BCv2Ci8R, I think the main area of concern is line 1, So bootstrap.php looks like http://pastebin.com/hVZhJAG1

UPDATE

I have found that the problem starts when I have the line

$schemaTool->dropSchema($classes);
$schemaTool->updateSchema($classes);

in bootstrap.php http://pastebin.com/hVZhJAG1


Solution

  • Its been sometime, but I think I fixed the problem by removing usage of Zend_Registry from bootstrap.php

    http://pastebin.com/BS79xviM