/** * @covers ::makeFromException */ public function test_makeFromException_return_if_already_instance_of_self() { // Given $e = new \Exception('ex message', 123); // When $apiEx = DatabaseException::makeFromException($e); $apiEx2 = DatabaseException::makeFromException($apiEx); // Then $this->assertSame($apiEx, $apiEx2); }
public function dbConnect() { if ($this->isConnected) { return $this; } mysqli_report(MYSQLI_REPORT_STRICT); try { $this->mysql = new \mysqli($this->config[DbConnector::DB_CFG_HOST], $this->config[DbConnector::DB_CFG_USERNAME], $this->config[DbConnector::DB_CFG_PASSWORD], $this->config[DbConnector::DB_CFG_DATABASE], $this->config[DbConnector::DB_CFG_PORT]); $this->mysql->set_charset('utf8'); } catch (\Exception $e) { throw DatabaseException::makeFromException($e); } $timezone = $this->config[DbConnector::DB_CFG_TIMEZONE]; if ($timezone) { $sql = sprintf($this->sqlSetTimezone, $timezone); if (!$this->mysql->query($sql)) { $msg = sprintf('Setting timezone (%s) for MySQL driver failed. Please load timezone information using mysql_tzinfo_to_sql.', $timezone); throw new DatabaseException($msg); } } $this->isConnected = true; return $this; }