From b94303462257aed71f2abfd09e9a3b9b2698636a Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Fri, 1 Mar 2024 20:38:27 +0100 Subject: [PATCH 1/7] FIX return in method put on api_ticket (#28563) * FIX return in method put on api_ticket * Update api_tickets.class.php * Update api_tickets.class.php --------- Co-authored-by: Laurent Destailleur --- htdocs/ticket/class/api_tickets.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/ticket/class/api_tickets.class.php b/htdocs/ticket/class/api_tickets.class.php index 6163ae449b2..28e87fc428f 100644 --- a/htdocs/ticket/class/api_tickets.class.php +++ b/htdocs/ticket/class/api_tickets.class.php @@ -382,11 +382,11 @@ class Tickets extends DolibarrApi $this->ticket->$field = $value; } - if ($this->ticket->update(DolibarrApiAccess::$user)) { + if ($this->ticket->update(DolibarrApiAccess::$user) > 0) { return $this->get($id); + } else { + throw new RestException(500, $this->ticket->error); } - - return false; } /** From 7e8b45f287ad0347ab9b01502b4273f709ede986 Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 1 Mar 2024 20:39:52 +0100 Subject: [PATCH 2/7] Qual: Improve PhpUnit logging in case of error. (#28562) # Qual: Improve PhpUnit logging in case of error. - Log exception message with extra log information. - Do not output markers for dolibarr.log if no log lines should be shown. - Use GitHub action style prefixes to group messages --- test/phpunit/CommonClassTest.class.php | 47 ++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/test/phpunit/CommonClassTest.class.php b/test/phpunit/CommonClassTest.class.php index 0e5f49dd24b..0322cdd28bc 100644 --- a/test/phpunit/CommonClassTest.class.php +++ b/test/phpunit/CommonClassTest.class.php @@ -116,11 +116,7 @@ abstract class CommonClassTest extends TestCase if ($t instanceof PHPUnit\Framework\Error\Notice) { $nbLinesToShow = 3; } - $totalLines = count($lines); - $first_line = max(0, $totalLines - $nbLinesToShow); - // Get the last line of the log - $last_lines = array_slice($lines, $first_line, $nbLinesToShow); $failedTestMethod = $this->getName(false); $className = get_called_class(); @@ -131,14 +127,25 @@ abstract class CommonClassTest extends TestCase // Get the test method's data set $argsText = $this->getDataSetAsString(true); - // Show log file + $totalLines = count($lines); + $first_line = max(0, $totalLines - $nbLinesToShow); + // Get the last line of the log + $last_lines = array_slice($lines, $first_line, $nbLinesToShow); + print PHP_EOL; - print "----- $className::$failedTestMethod failed - $argsText.".PHP_EOL; - print "Show last ".$nbLinesToShow." lines of dolibarr.log file -----".PHP_EOL; - foreach ($last_lines as $line) { - print $line.PHP_EOL; + // Use GitHub Action compatible group output (:warning: arguments not encoded) + print "##[group]$className::$failedTestMethod failed - $argsText.".PHP_EOL; + print "## Exception: {$t->getMessage()}".PHP_EOL; + + if ($nbLinesToShow) { + // Show partial log file contents when requested. + print "## Show last ".$nbLinesToShow." lines of dolibarr.log file -----".PHP_EOL; + foreach ($last_lines as $line) { + print $line.PHP_EOL; + } + print "## end of dolibarr.log for $className::$failedTestMethod".PHP_EOL; } - print "----- end of dolibarr.log for $className::$failedTestMethod".PHP_EOL; + print "##[endgroup]".PHP_EOL; parent::onNotSuccessfulTest($t); } @@ -359,4 +366,24 @@ abstract class CommonClassTest extends TestCase $this->assertDirectoryDoesNotExist($directory, $message); } } + + /** + * Assert that a file does not exist without triggering deprecation + * + * @param string $file The file to test + * @param string $message The message to show if the directory exists + * + * @return void + */ + protected function assertFileNotExistsCompat($file, $message = '') + { + $phpunitVersion = \PHPUnit\Runner\Version::id(); + + // Check if PHPUnit version is less than 9.0.0 + if (version_compare($phpunitVersion, '9.0.0', '<')) { + $this->assertFileNotExists($file, $message); + } else { + $this->assertFileDoesNotExist($file, $message); + } + } } From e39070af37f902d22feb6c820f6903a9116d4415 Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Fri, 1 Mar 2024 20:41:16 +0100 Subject: [PATCH 3/7] Fix return type by changin boot to string (#28557) --- htdocs/fourn/class/fournisseur.facture-rec.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.facture-rec.class.php b/htdocs/fourn/class/fournisseur.facture-rec.class.php index 8a85a32e37a..820c92baa11 100644 --- a/htdocs/fourn/class/fournisseur.facture-rec.class.php +++ b/htdocs/fourn/class/fournisseur.facture-rec.class.php @@ -1249,7 +1249,7 @@ class FactureFournisseurRec extends CommonInvoice * Format string to output with by striking the string if max number of generation was reached * * @param string $ret Default value to output - * @return boolean False by default, True if maximum number of generation is reached + * @return string False by default, True if maximum number of generation is reached */ public function strikeIfMaxNbGenReached($ret) { From e0c161e4c2ee6b5ce347b1f6da3345e06fe3e695 Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Fri, 1 Mar 2024 20:47:47 +0100 Subject: [PATCH 4/7] fix assigne variable (#28559) * fix assigne variable * Update paiement.php --------- Co-authored-by: Laurent Destailleur --- htdocs/fourn/facture/paiement.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index cb36f12fe4f..4f1c81602a1 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -311,7 +311,13 @@ if (empty($reshook)) { // Creation of payment line $paiement = new PaiementFourn($db); $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array of amounts + + $correctedAmounts = []; + foreach ($amounts as $key => $value) { + $correctedAmounts[$key] = (float) $value; + } + + $paiement->amounts = $correctedAmounts; // Array of amounts $paiement->multicurrency_amounts = $multicurrency_amounts; $paiement->multicurrency_code = $multicurrency_code; // Array with all currency of payments dispatching $paiement->multicurrency_tx = $multicurrency_tx; // Array with all currency tx of payments dispatching From 262f5ffd217c7e6c80b2de08c200b854515fe282 Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Fri, 1 Mar 2024 20:48:14 +0100 Subject: [PATCH 5/7] change assignement type to int (#28561) --- htdocs/website/class/website.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index b7fb7ec2c6b..f22db99fd9c 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -923,7 +923,7 @@ class Website extends CommonObject $this->lang = 'en'; $this->otherlang = 'fr,es'; $this->status = 1; - $this->fk_default_home = null; + $this->fk_default_home = 0; $this->virtualhost = 'http://myvirtualhost'; $this->fk_user_creat = $user->id; $this->fk_user_modif = $user->id; From 389d58284663efa9135d3ba7fe94b2faa7d365d2 Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Fri, 1 Mar 2024 20:48:52 +0100 Subject: [PATCH 6/7] Fix return in deleteLine and cast a variable to string (#28558) --- htdocs/fourn/class/api_supplier_invoices.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php index 00ba4fa8532..fe44a813231 100644 --- a/htdocs/fourn/class/api_supplier_invoices.class.php +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -474,7 +474,7 @@ class SupplierInvoices extends DolibarrApi $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paiement->paiementid = $payment_mode_id; - $paiement->paiementcode = dol_getIdFromCode($this->db, $payment_mode_id, 'c_paiement', 'id', 'code', 1); + $paiement->paiementcode = (string) dol_getIdFromCode($this->db, $payment_mode_id, 'c_paiement', 'id', 'code', 1); $paiement->num_payment = $num_payment; $paiement->note_public = $comment; @@ -704,7 +704,12 @@ class SupplierInvoices extends DolibarrApi $updateRes = $this->invoice->deleteLine($lineid); if ($updateRes > 0) { - return $this->get($id); + return array( + 'success' => array( + 'code' => 200, + 'message' => 'line '.$lineid.' deleted' + ) + ); } else { throw new RestException(405, $this->invoice->error); } From 351ea07229bdb53cf0825ef1c4d26de5526bf11a Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Fri, 1 Mar 2024 20:49:23 +0100 Subject: [PATCH 7/7] Fix return type when output is 1 (#28501) * Fix return type when output is 1 * update doc method --- htdocs/core/class/html.formcontract.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formcontract.class.php b/htdocs/core/class/html.formcontract.class.php index fc869901f01..954f0b6ea75 100644 --- a/htdocs/core/class/html.formcontract.class.php +++ b/htdocs/core/class/html.formcontract.class.php @@ -61,7 +61,7 @@ class FormContract * @param int $showRef Show customer and supplier reference on each contract (when found) * @param int $noouput 1=Return the output instead of display * @param string $morecss More CSS - * @return int Nbr of contract if OK, <0 if KO + * @return int|string If nooutput = 0: Nbr of contract if OK, <0 if KO, If nooutput = 1: The HTML select string */ public function select_contract($socid = -1, $selected = 0, $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0, $morecss = 'minwidth150') {