title: phpunit You cannot serialize or unserialize PDO instances
body: <p>I'm using PHPUnit with processIsolation="true" because I need to set cookie value in the code I'm testing, and without processIsolation="true" it can't be done. But in one of my test case, I'm getting the error:</p>
  
  <pre><code>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-&gt;__sleep()
  #1 -(394): serialize(Array)
  #2 -(536): __phpunit_run_isolated_test()
  #3 {main}
    thrown in - on line 394
  </code></pre>
  
  <p>Test case: </p>
  
  <pre><code>public function testUserCookieIsSavedToClicksTable()
  {
      $cookie = sha1('12345');
      $_COOKIE['user_cookie'] = $cookie;
      $offerId = 1;
      $tx = $this-&gt;getTx($offerId);
  
      // Go
      $this-&gt;controller = new ClickController(new Click(new Database(Cache::getInstance()), new Queue, new RedisStorage()));
      $this-&gt;runLocal([1, $this-&gt;userId], null);
  
      $sql = 'select * from clicks order by id desc limit 1';
      $click = $this-&gt;db-&gt;query($sql, [], 'fetch');
      $this-&gt;assertEquals($tx, $click['tx_id']);
      $this-&gt;assertEquals($click['user_cookie'], $cookie);
  }
  </code></pre>
  
  <p>This error is thrown  when calling any of <code>$this-&gt;assertEquals($tx, $click['tx_id']);</code> or <code>$this-&gt;assertEquals($click['user_cookie'], $cookie);</code>. But I can <code>var_dump</code> any variables used in those assertions. </p>
  
  <p>I tried all solutions from <a href="https://stackoverflow.com/questions/14492486/unserialize-error-when-runinseparateprocess">here</a> but they not working for me  </p>