/**
  * @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);
 }
Esempio n. 2
0
 /**
  *
  * Returns true if database table has rows where one of the given columns has one of the
  * given values.
  *
  * Example:
  *
  * <code>
  * if($this->hasRowWith(array("email" => "*****@*****.**"));
  * </code>
  *
  * @param array $columnsEqual
  *
  */
 public function hasRowWith(array $columnsEqual)
 {
     $sql = "select * from " . $this->parser->getTableName() . " where ";
     $sql .= implode("=? or ", array_keys($columnsEqual));
     $sql .= "=?";
     $row = $this->db->one($sql, array_values($columnsEqual));
     if (isset($row)) {
         return true;
     }
     return false;
 }
 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();
 }
Esempio n. 4
0
 /**
  * @test
  */
 public function shouldBeAbleToSignIn()
 {
     // given
     $this->createUser("username", "Pass1234");
     LudoDB::enableSqlLogging();
     /// when
     $login = new Session();
     $login->signIn(array("username" => "username", "password" => md5("Pass1234")));
     // then
     $this->assertNotNull($login->getKey());
     $this->assertTrue($login->isSignedIn());
 }
Esempio n. 5
0
 public function setUp()
 {
     if (!self::$connected) {
         date_default_timezone_set('Europe/Berlin');
         LudoDB::setHost('localhost');
         LudoDB::setUser('root');
         LudoDB::setPassword('administrator');
         LudoDB::setDb('PHPUnit');
         self::$connected = true;
         LudoDBRegistry::set('FILE_UPLOAD_PATH', '/tmp/');
     }
     if (!self::$logCleared) {
         self::$logCleared = true;
         $this->clearLog();
     }
     $classes = array('Game', 'Move', 'Database', 'Folder', 'Metadata', 'MetadataValue', 'Session', 'Seek', 'Chat', 'ChatMessage', 'ChatMessages', 'Fen', 'Player', 'TimeControl', 'ChessFileUpload', 'Elo', 'PasswordLookup');
     $util = new LudoDBUtility();
     $util->dropAndCreate($classes);
     $this->createAdminUserAndSignIn();
 }
Esempio n. 6
0
 /**
  * Return new LudoDB object with connection to the database.
  * @return LudoDB|LudoDBMySql|LudoDBMySqlI|LudoDBPDO
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         switch (self::$connectionType) {
             case self::ADAPTER_PDO:
                 self::$instance = new LudoDBPDO();
                 break;
             case self::ADAPTER_MYSQLI:
                 self::$instance = new LudoDBMySqlI();
                 break;
             case self::ADAPTER_PDO_ORACLE:
                 self::$instance = new LudoDBPDOOracle();
                 break;
             default:
                 self::$instance = new LudoDBMySql();
         }
         self::$instance->connect();
     }
     return self::$instance;
 }
 /**
  * @test
  */
 public function shouldDetermineDatabaseExistence()
 {
     $this->assertFalse(LudoDB::getInstance()->databaseExists('abcdefg'));
     $this->assertTrue(LudoDB::getInstance()->databaseExists('PHPUnit'));
 }
 public function shouldBeAbleToSpecifyLimitInSql()
 {
     // given
     LudoDB::enableSqlLogging();
     $this->createPeople();
     $people = new PeoplePaged(0, 10);
     $values = $people->getValues();
     // then
     $this->assertEquals(10, count($values));
 }
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: Alf Magne
 * Date: 23.01.13
 * Time: 14:52
 * To change this template use File | Settings | File Templates.
 */
ini_set('display_errors', 'on');
date_default_timezone_set("Europe/Berlin");
require_once __DIR__ . "/../autoload.php";
LudoDB::setHost('127.0.0.1');
LudoDB::setUser('root');
LudoDB::setPassword('administrator');
LudoDB::setDb('PHPUnit');
// Construct database tables
$tables = array('Move', 'Game', 'Fen', 'Metadata', 'MetadataValue');
foreach ($tables as $table) {
    $inst = new $table();
    $inst->drop()->yesImSure();
    $inst->createTable();
}
$profiling = new XHPProfiling('PGN to parser to DB');
$parser = new PgnParser("../../pgn/profiling.pgn");
$games = $parser->getGames();
foreach ($games as $gameData) {
    $game = new Game();
    $game->setDatabaseId(100);
    $game->setFen($gameData['metadata']['fen']);
    $game->setMetadata($gameData['metadata']);
 /**
  * Return data from handler in JSON format.
  * @param array $data
  * @return string
  */
 private function toJSON($data = array())
 {
     if ($this->success) {
         $this->message = $this->resource->getOnSuccessMessageFor($this->serviceName);
     }
     $ret = array('success' => $this->success, 'message' => $this->message, 'code' => $this->code, 'resource' => get_class($this->resource), 'service' => $this->serviceName, $this->responseKey => $data);
     if (LudoDB::isLoggingEnabled()) {
         $ret['log'] = array('time' => LudoDB::getElapsed(), 'queries' => LudoDB::getQueryCount());
     }
     return json_encode($ret);
 }
Esempio n. 11
0
<?php

/**
 * Your database connection details
 * User: Alf Magne Kalleland
 * Date: 23.02.13
 * Time: 06:07
 */
LudoDB::setUser('consultl_user');
LudoDB::setPassword('passwords123');
LudoDB::setHost('localhost');
LudoDB::setDb('consultl_dhtmlchess');
 /**
  * @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());
 }
Esempio n. 13
0
<?php

/**
 * Demo of nested collections. DemoCountries merges DemoStates
 * and DemoStates merges DemoCities.
 * User: Alf Magne Kalleland
 * Date: 09.02.13
 * Time: 16:34
 */
require_once __DIR__ . "/autoload.php";
ini_set('display_errors', 'on');
date_default_timezone_set("Europe/Berlin");
LudoDB::setDb("PHPUnit");
LudoDB::setUser("root");
LudoDB::setPassword("administrator");
LudoDB::setHost("127.0.0.1");
$c = new DemoCountry();
if (!$c->exists()) {
    $util = new LudoDBUtility();
    $util->dropAndCreate(array("DemoState", "DemoCity", "DemoCountry"));
}
LudoDB::enableLogging();
// get number of queries and server time in response
$handler = new LudoDBRequestHandler();
echo $handler->handle("DemoCountries/read");
 private function setConnectionDetails($dbDetails)
 {
     LudoDB::setDb($dbDetails['db']);
     LudoDB::setUser($dbDetails['username']);
     LudoDB::setPassword($dbDetails['password']);
     LudoDB::setHost($dbDetails['host']);
 }
Esempio n. 15
0
 /**
  * @test
  */
 public function shouldCreateRecordsInAcceptableTime_MYSQLI()
 {
     LudoDB::setConnectionType('MYSQLI');
     $this->startTimer();
     for ($i = 0; $i < 500; $i++) {
         $person = new Person();
         $person->setFirstname('John');
         $person->setLastname('Wayne');
         $person->setAddress('Somewhere');
         $person->setZip(4330);
         $person->commit();
     }
     $time = $this->getElapsed(__FUNCTION__);
     // then
     $this->assertLessThan(1.5, $time);
 }
<?php

/**
 * Your database connection details
 * User: Alf Magne Kalleland
 * Date: 23.02.13
 * Time: 06:07
 */
LudoDB::setUser('root');
LudoDB::setPassword('administrator');
LudoDB::setHost('127.0.0.1');
LudoDB::setDb('dhtml_chess');
Esempio n. 17
0
 /**
  * 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;
 }
Esempio n. 18
0
 protected function clearTable()
 {
     $db = LudoDB::getInstance();
     $db->query("delete from TestTable");
 }