/** * @test */ public function shouldFindUpdatedColumns() { // given $obj = new PersonForUtility(); $tableName = $obj->configParser()->getTableName(); $tableDef = LudoDB::getInstance()->getTableDefinition($tableName); $this->assertArrayHasKey("id", $tableDef, json_encode($tableDef)); $this->assertArrayHasKey("firstname", $tableDef); $this->assertArrayHasKey("zip", $tableDef); }
public function save($id) { if (!$this->exists()) { $this->createTable(); } LudoDB::getInstance()->query("delete from " . $this->configParser()->getTableName() . " where current=steps"); $this->setValue('id', $id); $this->setValue('steps', 1000); $this->setValue('text', ''); $this->setValue('current', 0); $this->commit(); }
/** * @test */ public function shouldDetermineDatabaseExistence() { $this->assertFalse(LudoDB::getInstance()->databaseExists('abcdefg')); $this->assertTrue(LudoDB::getInstance()->databaseExists('PHPUnit')); }
/** * Convert SQL string for prepared statement to standard SQL statement with values escaped(safe values). * @param $sql * @param array $params * @return string */ public static function fromPrepared($sql, $params = array()) { if (!strstr($sql, "?")) { return $sql; } $sql = str_replace("?", "'%s'", $sql); $sql = str_replace("''%s''", "'%s'", $sql); $db = LudoDB::getInstance(); for ($i = 0, $count = count($params); $i < $count; $i++) { $params[$i] = $db->escapeString($params[$i]); } $sql = vsprintf($sql, $params); return $sql; }
protected function clearTable() { $db = LudoDB::getInstance(); $db->query("delete from TestTable"); }
public function validateConnection($dbDetails) { ini_set('display_errors', 'off'); $keys = array("host", "username", "password", "db"); foreach ($keys as &$key) { if (!isset($dbDetails[$key])) { throw new LudoDBConnectionException("key " . $key . " is missing."); } $key = preg_replace("/[^a-z0-9_-]/si", "", $key); } $this->setConnectionDetails($dbDetails); try { LudoDB::getInstance(); } catch (LudoDBException $e) { LudoDB::setDb(""); LudoDB::getInstance()->connect(); LudoDB::createDatabase($dbDetails['db']); $this->setConnectionSuccessMessage('Connection successful. Database ' . $dbDetails['db'] . " created"); } return $dbDetails; }
/** * @test */ public function shouldBeAbleToDefineDefaultData() { // given $car = new Car(); $car->drop()->yesImSure(); $car->createTable(); new Car(); $db = LudoDB::getInstance(); $row = $db->one("select count(id) as num from car"); // then $this->assertEquals(7, $row['num']); $car = new Car(1); $this->assertEquals('Opel', $car->getBrand()); }