From 65a1883a53bd2f665d18c91a928517300a6da8c5 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 5 Nov 2016 11:56:03 +0100 Subject: [PATCH] [Database] is now [DatabaseDriver] and manages `multiple servers` --- autoloader.php | 3 + build/Builder.php | 17 ++ build/api/core/ModuleRequest.php | 2 +- build/api/module/download.php | 2 +- build/api/module/input.php | 2 +- build/api/module/subject.php | 3 +- build/api/module/token.php | 2 +- build/api/module/upload.php | 2 +- build/api/module/user.php | 2 +- .../core/{Database.php => DatabaseDriver.php} | 146 ++++++++++++++---- build/database/repo/parentRepo.php | 10 +- build/database/repo/token.php | 16 +- build/database/repo/user.php | 14 +- build/orm/core/Rows.php | 10 +- build/orm/core/SQLBuilder.php | 2 +- build/orm/core/Table.php | 12 +- config/database-lab-surveys.json | 6 + public_html/index.php | 55 +++---- public_html/view/settings.php | 4 +- test/automate.php | 2 +- test/phpunit/tests/Database_construct.php | 22 +-- test/phpunit/tests/Database_delNumeric.php | 12 +- .../phpunit/tests/Database_readableNumber.php | 42 ++--- 23 files changed, 247 insertions(+), 141 deletions(-) create mode 100644 build/Builder.php rename build/database/core/{Database.php => DatabaseDriver.php} (60%) create mode 100644 config/database-lab-surveys.json diff --git a/autoloader.php b/autoloader.php index 5d239f9..9345022 100644 --- a/autoloader.php +++ b/autoloader.php @@ -18,6 +18,9 @@ } + // Loads the build facade + require_once __BUILD__.'/Builder.php'; + /* AUTOLOADER * diff --git a/build/Builder.php b/build/Builder.php new file mode 100644 index 0000000..e084f24 --- /dev/null +++ b/build/Builder.php @@ -0,0 +1,17 @@ + __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 Database Server's host + * @dbname Database name + * @username Database username + * @password 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 [optional] Database Label + * @local [optional] Local configuration path + * @remote [optional] Remote configuration path + * + * @return status 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 [optional] Driver's label + * + * @return driver 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, diff --git a/build/database/repo/parentRepo.php b/build/database/repo/parentRepo.php index cd2afae..5d35d37 100644 --- a/build/database/repo/parentRepo.php +++ b/build/database/repo/parentRepo.php @@ -1,7 +1,7 @@ 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() ); } } diff --git a/build/database/repo/token.php b/build/database/repo/token.php index 23d0ff5..c80a66e 100644 --- a/build/database/repo/token.php +++ b/build/database/repo/token.php @@ -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 )); diff --git a/build/database/repo/user.php b/build/database/repo/user.php index ce796c6..f69e897 100644 --- a/build/database/repo/user.php +++ b/build/database/repo/user.php @@ -1,7 +1,7 @@ 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 )); } diff --git a/build/orm/core/Rows.php b/build/orm/core/Rows.php index 50516b1..dcb6394 100644 --- a/build/orm/core/Rows.php +++ b/build/orm/core/Rows.php @@ -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 diff --git a/build/orm/core/SQLBuilder.php b/build/orm/core/SQLBuilder.php index 02dd3ef..fd22412 100644 --- a/build/orm/core/SQLBuilder.php +++ b/build/orm/core/SQLBuilder.php @@ -2,7 +2,7 @@ namespace orm\core; - use \database\core\Database; + use \database\core\DatabaseDriver; use \orm\core\Rows; diff --git a/build/orm/core/Table.php b/build/orm/core/Table.php index 359ab7e..81c0880 100644 --- a/build/orm/core/Table.php +++ b/build/orm/core/Table.php @@ -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']; diff --git a/config/database-lab-surveys.json b/config/database-lab-surveys.json new file mode 100644 index 0000000..2ec7868 --- /dev/null +++ b/config/database-lab-surveys.json @@ -0,0 +1,6 @@ +{ + "host" : "shadowx-dev.com", + "dbname" : "cnrs", + "user" : "cnrs", + "password" : "yEHsPxCurd7RsynE" +} diff --git a/public_html/index.php b/public_html/index.php index b4746be..09891eb 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -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(); diff --git a/public_html/view/settings.php b/public_html/view/settings.php index ce5dfcc..6a13ea3 100644 --- a/public_html/view/settings.php +++ b/public_html/view/settings.php @@ -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 "
"; echo "".$token['name'].""; - echo "".Database::frDate($token['expires']).""; + echo "".DatabaseDriver::frDate($token['expires']).""; echo "
"; echo "".$token['token'].""; echo "
"; diff --git a/test/automate.php b/test/automate.php index 24ede7d..6560571 100644 --- a/test/automate.php +++ b/test/automate.php @@ -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; diff --git a/test/phpunit/tests/Database_construct.php b/test/phpunit/tests/Database_construct.php index a3a9a6e..506af16 100644 --- a/test/phpunit/tests/Database_construct.php +++ b/test/phpunit/tests/Database_construct.php @@ -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.'); } diff --git a/test/phpunit/tests/Database_delNumeric.php b/test/phpunit/tests/Database_delNumeric.php index bd1f445..cb201c3 100644 --- a/test/phpunit/tests/Database_delNumeric.php +++ b/test/phpunit/tests/Database_delNumeric.php @@ -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 ); diff --git a/test/phpunit/tests/Database_readableNumber.php b/test/phpunit/tests/Database_readableNumber.php index f01c2e8..e744e2b 100644 --- a/test/phpunit/tests/Database_readableNumber.php +++ b/test/phpunit/tests/Database_readableNumber.php @@ -1,5 +1,5 @@ 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 ); }