/** * @covers ::jsonSerialize */ public function test_jsonSerialize() { // Given $e = new DatabaseException('my message', 1234); // When $std = $e->jsonSerialize(); // Then $this->assertInstanceOf('stdClass', $std); $exp = ['code' => 1234, 'message' => 'my message']; $this->assertSame($exp, (array) $exp); }
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; }