From 3c8195c672b9ff3586f0b9ba61b1afa514a20c41 Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Mon, 12 Sep 2022 16:43:05 +0200
Subject: [PATCH] =?UTF-8?q?tests:=20fix=20diff=C3=A9rents=20petits=20glitc?=
 =?UTF-8?q?h=20(on=20ne=20peut=20pas=20tester=20!=3D=3D=20partout=20n'en?=
 =?UTF-8?q?=20d=C3=A9plaise=20aux=20outils=20de=20lint)=20+=20typages=20su?=
 =?UTF-8?q?r=20les=20tests=20legacy=20sql?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../abstract_sql/10_sql_insert_select.php     |  8 ++---
 .../abstract_sql/20_sql_update_delete.php     |  2 +-
 .../unit/abstract_sql/40_sql_divers.php       |  6 ++--
 .../unit/abstract_sql/inc-sql_datas.inc       | 36 +++++++++----------
 4 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/tests/legacy/unit/abstract_sql/10_sql_insert_select.php b/tests/legacy/unit/abstract_sql/10_sql_insert_select.php
index 9758a5338e..6d0ee83359 100644
--- a/tests/legacy/unit/abstract_sql/10_sql_insert_select.php
+++ b/tests/legacy/unit/abstract_sql/10_sql_insert_select.php
@@ -150,17 +150,17 @@ function test_selections()
 	}
 
 	// selection avec sql_multi
-	$res = sql_select(['id_tintin', sql_multi('grrrr', 'fr')], 'spip_test_milou', '', '', 'multi');
+	$res = sql_select(['id_milou', sql_multi('grrrr', 'fr')], 'spip_test_milou', '', '', 'multi');
 	if (sql_count($res) !== $nb_data) {
 		$err[] = 'sql_multi mal interprete';
 	}
 
 	$rs = sql_fetch($res);
-	$id1 = $rs['id_tintin'];
+	$id1 = intval($rs['id_milou']);
 	$rs = sql_fetch($res);
-	$id2 = $rs['id_tintin'];
+	$id2 = intval($rs['id_milou']);
 	$rs = sql_fetch($res);
-	$id3 = $rs['id_tintin'];
+	$id3 = intval($rs['id_milou']);
 	if ($id1 !== 3 && $id2 !== 2 && $id3 !== 1) {
 		$err[] = "sql_multi order by multi rate : ordre ({$id1}, {$id2}, {$id3}) - attendu : (3, 2, 1)";
 	}
diff --git a/tests/legacy/unit/abstract_sql/20_sql_update_delete.php b/tests/legacy/unit/abstract_sql/20_sql_update_delete.php
index daeeaad08f..eeb5ccad6c 100644
--- a/tests/legacy/unit/abstract_sql/20_sql_update_delete.php
+++ b/tests/legacy/unit/abstract_sql/20_sql_update_delete.php
@@ -37,7 +37,7 @@ function test_update_data()
 		'un_bigint' => 'un_bigint+2',
 	]);
 	$nb2 = sql_getfetsel('un_bigint', 'spip_test_tintin', 'id_tintin=' . sql_quote(1));
-	if ($nb + 2 !== $nb2) {
+	if ($nb + 2 != $nb2) {
 		$err[] = "sql_update n'a pas fait l'adition ! ({$nb} + 2 != {$nb2})";
 	}
 
diff --git a/tests/legacy/unit/abstract_sql/40_sql_divers.php b/tests/legacy/unit/abstract_sql/40_sql_divers.php
index 668e39c26e..8148428f6f 100644
--- a/tests/legacy/unit/abstract_sql/40_sql_divers.php
+++ b/tests/legacy/unit/abstract_sql/40_sql_divers.php
@@ -33,7 +33,7 @@ function test_func_mathematiques()
 		'AVG' => 3000,
 	] as $func => $attendu) {
 		$nb = sql_getfetsel("{$func}(un_int) AS nb", ['spip_test_tintin']);
-		if ($nb !== $attendu) {
+		if ($nb != $attendu) {
 			$err[] = "Selection {$func} en echec : attendu : {$attendu}, recu : {$nb}";
 		}
 	}
@@ -51,11 +51,11 @@ function test_func_mathematiques()
 		'1.5/2' => (1.5 / 2),
 		'2.0/2' => (2.0 / 2),
 		'2/2' => (2 / 2),
-		'md5(8)' => md5(8),
+		'md5(8)' => md5("8"),
 		'md5(' . sql_quote('a') . ')' => md5('a'),
 	] as $func => $attendu) {
 		$nb = sql_getfetsel("{$func} AS nb", ['spip_test_tintin'], ['id_tintin=' . sql_quote(1)]);
-		if ($nb !== $attendu) {
+		if ($nb != $attendu) {
 			$err[] = "Selection {$func} en echec : attendu : {$attendu}, recu : {$nb}";
 		}
 	}
diff --git a/tests/legacy/unit/abstract_sql/inc-sql_datas.inc b/tests/legacy/unit/abstract_sql/inc-sql_datas.inc
index 3f631b1c9d..7096c22a5b 100644
--- a/tests/legacy/unit/abstract_sql/inc-sql_datas.inc
+++ b/tests/legacy/unit/abstract_sql/inc-sql_datas.inc
@@ -2,15 +2,15 @@
 
 /*
  * Jeu de donnees pour les differents fichiers de tests sql
- * 
+ *
  * Quelques fonctions utilises souvent :
  * - test_create_table
  * - test_drop_table
  */
 
-/* 
- * tableaux des donnees 
- * 
+/*
+ * tableaux des donnees
+ *
  */
 function test_sql_datas(){
 	$table_tintin = [
@@ -26,9 +26,9 @@ function test_sql_datas(){
 			"maj" => "TIMESTAMP"
 		],
 		'key'=>[
-		
+
 		],
-		'nb_key_attendues'=>1 // attention : la primary key DOIT etre dans les cle aussi		
+		'nb_key_attendues'=>1 // attention : la primary key DOIT etre dans les cle aussi
 	];
 	$data_tintin = [
 		[
@@ -65,7 +65,7 @@ function test_sql_datas(){
 			//"maj" => "" // doit se remplir automatiquement
 		]
 	];
-	
+
 	$table_milou = [
 		'field'=> [
 			"id_milou" => "INTEGER NOT NULL AUTO_INCREMENT",
@@ -109,7 +109,7 @@ function test_sql_datas(){
 			// "maj" => "" // doit se remplir automatiquement
 		],
 	];
-	
+
 	$table_haddock = [
 		'field'=> [
 			"id_haddock" => "INTEGER NOT NULL AUTO_INCREMENT",
@@ -139,7 +139,7 @@ function test_sql_datas(){
 			"alcool" => "Un début de chaine : <multi>[fr]Vinasse[en]Vinassy</multi>, et [la fin]",
 		],
 	];
-			
+
 	return [
 		'spip_test_tintin'=>[
 			'desc'=>$table_tintin,
@@ -148,16 +148,16 @@ function test_sql_datas(){
 		'spip_test_milou'=>[
 			'desc'=>$table_milou,
 			'data'=>$data_milou
-			],				
+			],
 		'spip_test_haddock'=>[
 			'desc'=>$table_haddock,
 			'data'=>$data_haddock
-			],				
+			],
 	];
 }
 
 /*
- * Suppression de tables 
+ * Suppression de tables
  */
 function test_drop_table(){
 	$tables = test_sql_datas();
@@ -182,14 +182,14 @@ function test_create_table(){
 	foreach ($tables as $t=>$v){
 		if (!sql_create($t, $v['desc']['field'], $v['desc']['key']))
 			$err[] = "sql_create $t en echec"; // reponse, arguments
-	}		
+	}
 	if ($err) {
 		return '<b>Creation de table en echec</b><dl>' . join('', $err) . '</dl>';
 	}
 }
 
 
-	
+
 /*
  * Insertion de champs multiples sql_insertq_multi
  * et comptage avec sql_countsel
@@ -200,12 +200,12 @@ function test_insert_data() {
 	// inserer les donnees dans la table
 	foreach ($tables as $t=>$d){
 		sql_insertq_multi($t, $d['data']);
-		$essais[] = [(string)count($d['data']),$t];
+		$essais[] = [count($d['data']),$t];
 	}
-	$err = tester_fun('sql_countsel', $essais);	
+	$err = tester_fun('sql_countsel', $essais);
 	if ($err) {
 		return '<b>Insertion multiple puis countsel dans table</b><dl>' . join('', $err) . '</dl>';
-	}	
+	}
 }
-		
+
 ?>
-- 
GitLab