【发布时间】:2018-05-14 06:32:02
【问题描述】:
我正在使用带有 processIsolation="true" 的 PHPUnit,因为我需要在我正在测试的代码中设置 cookie 值,而没有 processIsolation="true" 则无法完成。但在我的一个测试用例中,我收到了错误:
PHPUnit_Framework_Exception: [10-May-2018 15:23:28 UTC] PHP Fatal error: Uncaught PDOException: You cannot serialize or unserialize PDO instances in -:394
Stack trace:
#0 [internal function]: PDO->__sleep()
#1 -(394): serialize(Array)
#2 -(536): __phpunit_run_isolated_test()
#3 {main}
thrown in - on line 394
测试用例:
public function testUserCookieIsSavedToClicksTable()
{
$cookie = sha1('12345');
$_COOKIE['user_cookie'] = $cookie;
$offerId = 1;
$tx = $this->getTx($offerId);
// Go
$this->controller = new ClickController(new Click(new Database(Cache::getInstance()), new Queue, new RedisStorage()));
$this->runLocal([1, $this->userId], null);
$sql = 'select * from clicks order by id desc limit 1';
$click = $this->db->query($sql, [], 'fetch');
$this->assertEquals($tx, $click['tx_id']);
$this->assertEquals($click['user_cookie'], $cookie);
}
调用$this->assertEquals($tx, $click['tx_id']); 或$this->assertEquals($click['user_cookie'], $cookie); 时会引发此错误。但我可以var_dump 这些断言中使用的任何变量。
我尝试了here 的所有解决方案,但它们对我不起作用
【问题讨论】:
标签: phpunit