[Database] is now [DatabaseDriver] and manages `multiple servers`

This commit is contained in:
xdrm-brackets 2016-11-05 11:56:03 +01:00
parent 64e3ce58ac
commit 65a1883a53
23 changed files with 247 additions and 141 deletions

View File

@ -18,6 +18,9 @@
}
// Loads the build facade
require_once __BUILD__.'/Builder.php';
/* AUTOLOADER
*

17
build/Builder.php Normal file
View File

@ -0,0 +1,17 @@
<?php
/**************************
* Builder *
* 05-11-16 *
***************************
* Designed & Developed by *
* xdrm-brackets *
***************************
* https://xdrm.io/ *
**************************/
class Builder{
}

View File

@ -1,7 +1,7 @@
<?php
namespace api\core;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\ManagerError;
use \api\core\Checker;

View File

@ -1,7 +1,7 @@
<?php
namespace api\module;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\sessionManager;
use \api\core\ModuleRequest;
use \manager\ManagerError;

View File

@ -2,7 +2,7 @@
namespace api\module;
use \manager\sessionManager;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\ManagerError;
use \api\core\ModuleRequest;
use \database\core\Repo;

View File

@ -2,7 +2,7 @@
namespace api\module;
use \manager\sessionManager;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\ManagerError;
use \database\core\Repo;
use \lightdb\core\lightdb;
@ -218,6 +218,7 @@
public static function search($params){
extract($params);
// Contiendra les sujets
$subjects = [];

View File

@ -1,7 +1,7 @@
<?php
namespace api\module;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \api\core\Checker;
use \manager\sessionManager;
use \manager\ManagerError;

View File

@ -1,7 +1,7 @@
<?php
namespace api\module;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\sessionManager;
use \api\core\ModuleRequest;
use \manager\ManagerError;

View File

@ -2,7 +2,7 @@
namespace api\module;
use \manager\sessionManager;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\ManagerError;
use \database\core\Repo;

View File

@ -4,81 +4,165 @@
use \manager\ManagerError;
class DataBase{
class DataBaseDriver{
/* ATTRIBUTS STATIQUES */
public static function config_path(){
/* STATIC ATTRIBUTES */
public static function default_path(){
return [
'local' => __CONFIG__.'/database-local.json',
'remote' => __CONFIG__.'/database.json'
];
}
private static $pdo;
private static $instance;
private static $path; // Databases configurations files
private static $config; // PDO configurations
private static $instance = []; // Database driver instance list
/* ATTRIBUTS */
public $error;
/* ATTRIBUTES */
private $host;
private $dbname;
private $username;
private $password;
public static $error;
private $pdo;
public function __construct($host, $dbname, $username, $password){
/* CONSTRUCTOR OF A DATABASE DRIVER
*
* @host<String> Database Server's host
* @dbname<String> Database name
* @username<String> Database username
* @password<String> Database password
*
*/
private function __construct($host, $dbname, $username, $password){
/* (2) Stores configuration */
$this->host = $host;
$this->dbname = $dbname;
$this->username = $username;
$this->password = $password;
try{
self::$pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password);
$this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password);
// On signale que tout s'est bien passe
self::$error = ManagerError::Success;
$this->error = ManagerError::Success;
}catch(Exception $e){
// On signale qu'il y a une erreur
self::$error = ManagerError::PDOConnection;
$this->error = ManagerError::PDOConnection;
}
}
/* retourne une instance de la classe */
public static function getInstance(){
if( self::$instance == null || self::$error != ManagerError::Success ){ // Si aucune instance existante OU erreur de connection
// chargement de la configuration du server SQL
/************************************************
**** Multiton Management (static) ****
************************************************/
/* ADDS A NEW CONNECTION
*
* @label<String> [optional] Database Label
* @local<String> [optional] Local configuration path
* @remote<String> [optional] Remote configuration path
*
* @return status<Boolean> If added successfully
*
*/
public static function add($label=null, $local=null, $remote=null){
/* [1] Default values
=========================================================*/
/* (1) If label isn't given */
is_null($label) && ($label = 'default');
/* (2) If label and no path */
if( $label !== 'default' && (is_null($local) || is_null($remote)) )
return false;
/* [2] Stores paths
=========================================================*/
/* (1) If not default, stores new values */
if( $label !== 'default' )
self::$path[$label] = [ 'local' => $local, 'remote' => $remote ];
/* (2) If default, fetch default path */
else
self::$path[$label] = self::default_path();
/* [3] Test configuration paths
=========================================================*/
/* (1) If paths aren't files */
if( !is_file(self::$path[$label]['local']) || !is_file(self::$path[$label]['remote']) )
return false;
/* (2) If paths aren't JSON */
$jLocal = json_decode( file_get_contents(self::$path[$label]['local']), true );
$jRemote = json_decode( file_get_contents(self::$path[$label]['remote']), true );
if( !is_array($jLocal) || !is_array($jRemote) )
return false;
/* [4] Instanciates the driver
=========================================================*/
try{
/* (1) If local -> instanciates with local configuration */
if( !checkdnsrr($_SERVER['SERVER_NAME'], 'NS') )
$conf = json_decode( file_get_contents(self::config_path()['local']), true );
self::$instance[$label] = new DatabaseDriver($jLocal['host'], $jLocal['dbname'], $jLocal['user'], $jLocal['password']);
/* (2) If Remote -> instanciates with Remote configuration */
else
$conf = json_decode( file_get_contents(self::config_path()['remote']), true );
self::$instance[$label] = new DatabaseDriver($jRemote['host'], $jRemote['dbname'], $jRemote['user'], $jRemote['password']);
// creation de l'instance en fonction des parametres
self::$instance = new DataBase($conf['host'], $conf['dbname'], $conf['user'], $conf['password']);
return true;
}catch(\Exception $e){
/* (3) If fails */
return false;
}
return self::$instance;
}
/* GET A DATABASE DRIVER INSTANCE
*
* @label<String> [optional] Driver's label
*
* @return driver<Database> Multiton
*
*/
public static function get($label=null){
/* [1] Checks arguments
=========================================================*/
/* (1) Label default value */
is_null($label) && ($label = 'default');
/* (2) If no label, or unknown label */
if( is_null($label) || !isset(self::$instance[$label]) )
throw new \Exception('Database @label is incorrect.');
/* [2] Returns instance
=========================================================*/
return self::$instance[$label];
}
/* retourne la connection statique */
public static function getPDO(){
$instance = self::getInstance();
public static function getPDO($label=null){
$instance = self::get($label);
return self::$pdo;
return $instance->pdo;
}
public function getConfig(){
return [
'host' => $this->host,

View File

@ -1,7 +1,7 @@
<?php
namespace database\repo;
use \database\core\Database;
use \database\core\DatabaseDriver;
class parentRepo{
@ -30,8 +30,8 @@
/* [2] On charge la liste des colonnes de la table
=========================================================*/
$getColumns = Database::getPDO()->query('SHOW COLUMNS FROM '.static::table_name());
$cols = Database::delNumeric( $getColumns->fetchAll() );
$getColumns = DatabaseDriver::getPDO()->query('SHOW COLUMNS FROM '.static::table_name());
$cols = DatabaseDriver::delNumeric( $getColumns->fetchAll() );
$table_columns = [
'_PRIMARY_' => [] // Contiendra les champs de la clé primaire
@ -84,7 +84,7 @@
$getRequestString .= ' ORDER BY 1 ASC';
// On prépare la requête
$getRequest = Database::getPDO()->prepare($getRequestString);
$getRequest = DatabaseDriver::getPDO()->prepare($getRequestString);
/* [5] On exécute la requête
@ -107,7 +107,7 @@
/* [6] On récupère le résultat
=========================================================*/
return Database::delNumeric( $getRequest->fetchAll() );
return DatabaseDriver::delNumeric( $getRequest->fetchAll() );
}
}

View File

@ -4,7 +4,7 @@
namespace database\repo;
use \manager\sessionManager;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \api\core\Checker;
class token extends parentRepo{
@ -38,14 +38,14 @@
public static function getAll(){
/* [1] On prepare et execute la requete
=========================================================*/
$request = Database::getPDO()->query("SELECT id_token, name, token, expires, (CURDATE() > expires) as expired
$request = DatabaseDriver::getPDO()->query("SELECT id_token, name, token, expires, (CURDATE() > expires) as expired
FROM api_token
ORDER BY expires DESC");
/* [3] On retourne les donnees
=========================================================*/
return Database::delNumeric( $request->fetchAll() );
return DatabaseDriver::delNumeric( $request->fetchAll() );
}
@ -66,7 +66,7 @@
/* [1] Verification dans la base de donnees
=========================================================*/
$check = Database::getPDO()->prepare("SELECT id_token, permission
$check = DatabaseDriver::getPDO()->prepare("SELECT id_token, permission
FROM api_token
WHERE CURDATE() <= expires
AND token = :token");
@ -112,7 +112,7 @@
$token = sessionManager::sha1(uniqid());
// Verification dans la BDD
$check = Database::getPDO()->prepare("SELECT id_token FROM api_token WHERE token = :token");
$check = DatabaseDriver::getPDO()->prepare("SELECT id_token FROM api_token WHERE token = :token");
$check->execute( array( ':token' => $token ) );
// VRAI un token est identique
@ -122,7 +122,7 @@
/* [2] On cree le token
=========================================================*/
$create = Database::getPDO()->prepare("INSERT INTO api_token(id_token, token, name, expires)
$create = DatabaseDriver::getPDO()->prepare("INSERT INTO api_token(id_token, token, name, expires)
VALUES(DEFAULT, :token, :name, :expiration)");
$create->execute(array(
':token' => $token,
@ -132,7 +132,7 @@
/* [3] On verifie qu'il a bien ete cree
=========================================================*/
$created = Database::getPDO()->prepare("SELECT id_token FROM api_token
$created = DatabaseDriver::getPDO()->prepare("SELECT id_token FROM api_token
WHERE token = :token
AND name = :name");
$created->execute(array(
@ -175,7 +175,7 @@
/* [2] Suppression du token
=========================================================*/
$remove = Database::getPDO()->prepare("DELETE FROM api_token
$remove = DatabaseDriver::getPDO()->prepare("DELETE FROM api_token
WHERE id_token = :id_token");
$remove->execute(array( ':id_token' => $id_token ));

View File

@ -1,7 +1,7 @@
<?php
namespace database\repo;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \api\core\Checker;
use \manager\sessionManager;
use \database\repo\parentRepo;
@ -32,7 +32,7 @@
/* [1] On verifie son login/password dans la BDD
=========================================================*/
$check = Database::getPDO()->prepare("SELECT id_user, login
$check = DatabaseDriver::getPDO()->prepare("SELECT id_user, login
FROM users
WHERE ( login = :username OR mail = :mail ) AND password = :password");
$check->execute(array(
@ -49,7 +49,7 @@
// On retourne le resultat
return Database::delNumeric( $result );
return DatabaseDriver::delNumeric( $result );
}
@ -79,7 +79,7 @@
/* [1] On verifie que le login/mail et reference sont uniques
=========================================================*/
$checkUnique = Database::getPDO()->prepare("SELECT id_user
$checkUnique = DatabaseDriver::getPDO()->prepare("SELECT id_user
FROM users
WHERE login = :login
OR mail = :mail ");
@ -94,7 +94,7 @@
/* [2] Creation de l'utilisateur
=========================================================*/
$create = Database::getPDO()->prepare("INSERT INTO users(id_user, login, password, mail)
$create = DatabaseDriver::getPDO()->prepare("INSERT INTO users(id_user, login, password, mail)
VALUES(DEFAULT, :login, :password, :mail)");
$create->execute(array(
':login' => $login,
@ -104,7 +104,7 @@
/* [3] Verification de la creation + recuperation id
=========================================================*/
$checkCreate = Database::getPDO()->prepare("SELECT id_user
$checkCreate = DatabaseDriver::getPDO()->prepare("SELECT id_user
FROM users
WHERE login = :login
AND password = :password
@ -142,7 +142,7 @@
public static function remove($id_user){
/* [1] On effectue la suppression
=========================================================*/
$getUser = Database::getPDO()->prepare("DELETE FROM users WHERE id_user = :id_user");
$getUser = DatabaseDriver::getPDO()->prepare("DELETE FROM users WHERE id_user = :id_user");
$getUser->execute(array( ':id_user' => $id_user ));
}

View File

@ -2,7 +2,7 @@
namespace orm\core;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \orm\core\SQLBuilder;
@ -511,7 +511,7 @@
$requestString = SQLBuilder::BUILD($requestS).';';
/* (2) On prépare la requête */
$request = Database::getPDO()->prepare($requestString);
$request = DatabaseDriver::getPDO()->prepare($requestString);
@ -636,7 +636,7 @@
/* [2] On bind les paramètres et exécute la requête
=========================================================*/
/* (0) On initialise la requête et les paramètres */
$request = Database::getPDO()->prepare($requestS.';');
$request = DatabaseDriver::getPDO()->prepare($requestS.';');
$bound = [];
/* (1) On bind les paramètres */
@ -728,7 +728,7 @@
$requestString = SQLBuilder::BUILD($requestS).';';
/* (2) On prépare la requête */
$request = Database::getPDO()->prepare($requestString);
$request = DatabaseDriver::getPDO()->prepare($requestString);
/* [5] On exécute la requête et retourne le résultat
=========================================================*/
@ -893,7 +893,7 @@
$requestString = SQLBuilder::BUILD($requestS).';';
/* (3) On prépare la requête */
$request = Database::getPDO()->prepare($requestString);
$request = DatabaseDriver::getPDO()->prepare($requestString);
// var_dump($requestString);
/* [8] On exécute la requête et retourne le résultat

View File

@ -2,7 +2,7 @@
namespace orm\core;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \orm\core\Rows;

View File

@ -3,7 +3,7 @@
namespace orm\core;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \manager\ManagerError;
use \orm\core\Rows;
@ -34,8 +34,8 @@
/* [1] On vérifie que la table existe
=========================================================*/
/* (1) Requête */
$checkTable = Database::getPDO()->query("SHOW tables FROM ".self::$database);
$checkTableResult = Database::delNumeric( $checkTable->fetchAll() );
$checkTable = DatabaseDriver::getPDO()->query("SHOW tables FROM ".self::$database);
$checkTableResult = DatabaseDriver::delNumeric( $checkTable->fetchAll() );
/* (2) On met en forme les données */
$tables = [];
@ -54,8 +54,8 @@
/* [2] Si la table existe, on récupère les colonnes
=========================================================*/
/* (1) On récupère les colonnes */
$getColumns = Database::getPDO()->query("SHOW columns FROM ".self::$database.'.'.$table_name);
$columnsResult = Database::delNumeric( $getColumns->fetchAll() );
$getColumns = DatabaseDriver::getPDO()->query("SHOW columns FROM ".self::$database.'.'.$table_name);
$columnsResult = DatabaseDriver::delNumeric( $getColumns->fetchAll() );
/* (2) On met en forme les données */
$columns = [];
@ -85,7 +85,7 @@
/* [3] On récupère les clés étrangères
=========================================================*/
/* (1) On récupère le texte du 'CREATE TABLE' */
$getCreateTable = Database::getPDO()->query("show create table ".$table_name);
$getCreateTable = DatabaseDriver::getPDO()->query("show create table ".$table_name);
if( is_bool($getCreateTable) )
throw new \Exception('[*] Cannot fetch constrains');
$create_table = $getCreateTable->fetch()['Create Table'];

View File

@ -0,0 +1,6 @@
{
"host" : "shadowx-dev.com",
"dbname" : "cnrs",
"user" : "cnrs",
"password" : "yEHsPxCurd7RsynE"
}

View File

@ -6,7 +6,7 @@
use \api\core\ModuleRequest;
use \api\core\ModuleResponse;
use \manager\ManagerError;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \api\core\Checker;
use \manager\MenuManager;
@ -22,19 +22,22 @@
define('__REDIRECT__', 'Location: /dashboard/');
/* [x] Gestion des utilisateurs
/* [1] Set databases
=========================================================*/
/* (1) Valeurs par defaut */
DatabaseDriver::add();
DatabaseDriver::add('lab-surveys', __CONFIG__.'/database-lab-surveys.json', __CONFIG__.'/database-lab-surveys.json');
/* [2] Identity Management
=========================================================*/
/* (1) Session initialization */
if( !isset($_SESSION['userid']) ) $_SESSION['userid'] = null;
if( !isset($_SESSION['username']) ) $_SESSION['username'] = null;
if( !isset($_SESSION['permission']) ) $_SESSION['permission'] = [];
/* (2) Gestion de la connection */
$login_vars = isset($_POST['login-sub']);
$login_vars = $login_vars && isset($_POST['login']);
$login_vars = $login_vars && isset($_POST['password']);
/* (2) Sign-In management */
$login_vars = isset($_POST['login-sub']) && isset($_POST['login']) && isset($_POST['password']);
// Status de login
$_SESSION['login_status'] = 'no';
@ -50,16 +53,11 @@
$_SESSION['login_status'] = 'logged';
// Si on n'a pas les bonnes donnees
else
else
$_SESSION['login_status'] = 'error';
}
// var_dump($login_vars);
// var_dump($_SESSION);
// exit();
/* (3) Gestion de le deconnexion */
/* (3) Log-Out management */
$logout_vars = isset($_POST['logout-sub']);
// Si on se deconnecte
@ -78,13 +76,13 @@
/* [0] On initialise le routeur
/* [3] On initialise le routeur
===================================================*/
/* (1) New Router */
$R = new Router( $_GET['url'] );
/* (2) Gestion des SVG avec couleur modifiée */
// path/to/resource/filename@HEXADE.svg
/* (2) path/to/resource/filename@0hexa0.svg -> update svg content */
$R->get('(.+)@([a-f0-9]{6})(\.svg)', function($matches){
$path = __PUBLIC__.'/'.$matches[0].$matches[2];
@ -108,25 +106,23 @@
});
/* [1] On cree les regles de routage
/* [4] / -> homepage
===================================================*/
// Racine -> page d'accueil
$R->get('/?', function(){ header(__REDIRECT__); });
/* [2] On recupere la liste des pages du site
/* [5] Manage websites pages
=========================================================*/
$temporaryMenuInflater = new MenuManager();
$views = $temporaryMenuInflater->getCategories();
// nomPage/arg1/arg2 -> inclusion de la page
// pagename/arg1/arg2 -> include view
$R->get('(?:'.implode('|', $views).')(?:/[\w-]+)*/?', function(){ include __PUBLIC__.'/view.php'; });
// Api
/* [6] host.xxx/api/{module}/{method} -> api
=========================================================*/
$R->post('api(?:/(.*))?', function($url){
$request = ModuleRequest::fromPost($url, $_POST);
$answer = $request->dispatch();
@ -138,14 +134,13 @@
});
// N'importe -> page d'accueil
$R->get('.+', function(){ header(__REDIRECT__); });
/* [7] Any other URL -> homepage
=========================================================*/
$R->get('.+', function(){ header(__REDIRECT__); });
$R->post('.+', function(){ header(__REDIRECT__); });
/* [3] On lance le routeur
/* [8] Launch Router
===================================================*/
$R->run();

View File

@ -3,7 +3,7 @@
use \database\core\Repo;
use \api\core\ModuleRequest;
use \manager\ManagerError;
use \database\core\Database;
use \database\core\DatabaseDriver;
debug();
@ -60,7 +60,7 @@ if( permission('admin') ){
echo "<div>";
echo "<span>".$token['name']."</span>";
echo "<span data-prefix='Expiration'>".Database::frDate($token['expires'])."</span>";
echo "<span data-prefix='Expiration'>".DatabaseDriver::frDate($token['expires'])."</span>";
echo "</div><div>";
echo "<span><span class='flag'>".$token['token']."</span></span>";
echo "</div>";

View File

@ -8,7 +8,7 @@
use \manager\sessionManager;
use \manager\ManagerError;
use \database\core\Repo;
use \database\core\Database;
use \database\core\DatabaseDriver;
use \lightdb\core\lightdb;
use \api\client;

View File

@ -5,17 +5,17 @@
/* [1] Verification du chargement de la config
=========================================================*/
public function testGetInstanceWithNoSERVER(){
$instance = \database\core\Database::getInstance();
$instance = \database\core\DatabaseDriver::getInstance();
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
}
public function testGetInstanceWithSERVERLocal(){
// Pour regenerer une instance, on definit une erreur
\database\core\Database::$error = \manager\ManagerError::PDOConnection;
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
$instance = \database\core\Database::getInstance();
$instance = \database\core\DatabaseDriver::getInstance();
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
}
@ -25,20 +25,20 @@
/* [2] Verification du singleton (getInstance)
=========================================================*/
public function testInstancePersistence(){
\database\core\Database::$error = \manager\ManagerError::PDOConnection;
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
$instance_construct = \database\core\Database::getInstance();
$instance_nextuse = \database\core\Database::getInstance();
$instance_construct = \database\core\DatabaseDriver::getInstance();
$instance_nextuse = \database\core\DatabaseDriver::getInstance();
$this->assertSame( $instance_construct, $instance_nextuse );
}
public function testInstancePersistenceRefutation(){
\database\core\Database::$error = \manager\ManagerError::PDOConnection;
$instance_construct = \database\core\Database::getInstance();
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
$instance_construct = \database\core\DatabaseDriver::getInstance();
\database\core\Database::$error = \manager\ManagerError::PDOConnection;
$instance_nextuse = \database\core\Database::getInstance();
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
$instance_nextuse = \database\core\DatabaseDriver::getInstance();
$this->assertNotSame( $instance_construct, $instance_nextuse );
}
@ -48,7 +48,7 @@
/* [3] Verification de l'objet PDO
=========================================================*/
public function testPDO(){
$pdo = \database\core\Database::getPDO();
$pdo = \database\core\DatabaseDriver::getPDO();
$this->assertGreaterThan( 0, count($pdo->query('SELECT * FROM users')->fetchAll()), '[!] Aucun utilisateur trouve.');
}

View File

@ -5,11 +5,11 @@
/* [0] Verification du type
=========================================================*/
public function testTypeInt(){
$this->assertEquals( [], \database\core\Database::delNumeric(10) );
$this->assertEquals( [], \database\core\DatabaseDriver::delNumeric(10) );
}
public function testTypeString(){
$this->assertEquals( [], \database\core\Database::delNumeric('notarray') );
$this->assertEquals( [], \database\core\DatabaseDriver::delNumeric('notarray') );
}
/* [1] Verification pour 2 dimensions
@ -23,7 +23,7 @@
1 => 'Jean Dupont',
));
$computed_array = \database\core\Database::delNumeric( $fetchData );
$computed_array = \database\core\DatabaseDriver::delNumeric( $fetchData );
$this->assertArrayHasKey( 'id', $computed_array[0] );
$this->assertArrayHasKey( 'nom', $computed_array[0] );
@ -46,7 +46,7 @@
7 => 'Bla'
));
$computed_array = \database\core\Database::delNumeric( $fetchData );
$computed_array = \database\core\DatabaseDriver::delNumeric( $fetchData );
$this->assertArrayHasKey( 'id', $computed_array[0] );
$this->assertArrayHasKey( 'nom', $computed_array[0] );
@ -73,7 +73,7 @@
1 => 'Jean Dupont'
);
$computed_array = \database\core\Database::delNumeric( $fetchData );
$computed_array = \database\core\DatabaseDriver::delNumeric( $fetchData );
$this->assertArrayHasKey( 'id', $computed_array );
$this->assertArrayHasKey( 'nom', $computed_array );
@ -96,7 +96,7 @@
7 => 'Bla'
);
$computed_array = \database\core\Database::delNumeric( $fetchData );
$computed_array = \database\core\DatabaseDriver::delNumeric( $fetchData );
$this->assertArrayHasKey( 'id', $computed_array );
$this->assertArrayHasKey( 'nom', $computed_array );

View File

@ -1,5 +1,5 @@
<?php namespace phpunit;
use \database\core\Database;
use \database\core\DatabaseDriver;
class Database_readableNumber extends \PHPUnit_Framework_TestCase{
@ -9,43 +9,43 @@
/* [1] Gestion du formattage+affichage des numéros
=========================================================*/
public function testA(){
$this->assertEquals( Database::readableNumber('0102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('01 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('01 02 03 04 05'), $this->formatted );
}
public function testB(){
$this->assertEquals( Database::readableNumber('+33102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('+331 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('+33102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('+331 02 03 04 05'), $this->formatted );
}
public function testC(){
$this->assertEquals( Database::readableNumber('33102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('331 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('33102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('331 02 03 04 05'), $this->formatted );
}
public function testCbis(){
$this->assertEquals( Database::readableNumber('033102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('0331 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('033102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0331 02 03 04 05'), $this->formatted );
}
public function testBter(){
$this->assertEquals( Database::readableNumber('0033102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('00331 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0033102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('00331 02 03 04 05'), $this->formatted );
}
public function testFirstSpace(){
$this->assertEquals( Database::readableNumber('0 102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('+33 102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('33 102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('033 102030405'), $this->formatted );
$this->assertEquals( Database::readableNumber('0033 102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0 102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('+33 102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('33 102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('033 102030405'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0033 102030405'), $this->formatted );
}
public function testAllSpaces(){
$this->assertEquals( Database::readableNumber('0 1 02 03 04 05'), $this->formatted );
$this->assertEquals( Database::readableNumber('+33 1 02 03 04 05'), $this->formatted );
$this->assertEquals( Database::readableNumber('33 1 02 03 04 05'), $this->formatted );
$this->assertEquals( Database::readableNumber('033 1 02 03 04 05'), $this->formatted );
$this->assertEquals( Database::readableNumber('0033 1 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0 1 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('+33 1 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('33 1 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('033 1 02 03 04 05'), $this->formatted );
$this->assertEquals( DatabaseDriver::readableNumber('0033 1 02 03 04 05'), $this->formatted );
}