/** * @dataProvider exceptionProvider * * @param $exception * @param $code * @param $contains */ public function testExceptions($exception, $code, $contains) { $formed = PdoException::from($exception); $this->assertInstanceOf('\\Packaged\\Dal\\Exceptions\\Connection\\PdoException', $formed); $this->assertEquals($code, $formed->getCode()); if (is_array($contains)) { foreach ($contains as $contain) { $this->assertContains($contain, $formed->getMessage()); } } else { $this->assertContains($contains, $formed->getMessage()); } $this->assertSame($exception, $formed->getPrevious()); }
/** * Should we reconnect to the database after this sort of error? * * @param PdoException $e * * @return bool */ private function _shouldReconnectAfterException(PdoException $e) { // 2006 = MySQL server has gone away // 1047 = ER_UNKNOWN_COM_ERROR - happens when a PXC node is resyncing: // "WSREP has not yet prepared node for application use" // HY000 = General SQL error $codes = ['2006', '1047', 'HY000']; $p = $e->getPrevious(); return in_array((string) $e->getCode(), $codes, true) || $p && in_array((string) $p->getCode(), $codes, true); }