From 003fccf58b48b1b578dae01655e53e32e62b9c27 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Mon, 6 Oct 2025 16:38:39 +0200 Subject: [PATCH] Improve PHPUNIT --- unit-test/global.example.php | 3 ++- unit-test/global.php | 3 ++- unit-test/include/class/DocumentTest.php | 2 +- unit-test/include/class/acc_ledger_purchaseTest.php | 4 ++++ unit-test/include/class/acc_ledger_saleTest.php | 12 ++++++++++-- unit-test/include/class/periodeTest.php | 4 ++-- unit-test/include/lib/http_inputTest.php | 5 +++-- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/unit-test/global.example.php b/unit-test/global.example.php index f5e02160c..445cb8833 100644 --- a/unit-test/global.example.php +++ b/unit-test/global.example.php @@ -22,11 +22,12 @@ /* * Global variables */ -global $g_connection,$g_parameter,$g_user; +global $g_connection,$g_parameter,$g_user,$cn; if (!defined("DOSSIER"))define ("DOSSIER",25); $_REQUEST['gDossier'] = DOSSIER; $g_connection=new Database(DOSSIER); +$cn=&$g_connection; $g_parameter = new Noalyss_Parameter_Folder($g_connection); $_SESSION[SESSION_KEY.'use_name']='unit test'; $_SESSION[SESSION_KEY.'use_first_name']='automatic'; diff --git a/unit-test/global.php b/unit-test/global.php index c8b0ac956..bc387c25e 100644 --- a/unit-test/global.php +++ b/unit-test/global.php @@ -23,11 +23,12 @@ /* * Global variables */ -global $g_connection,$g_parameter,$g_user; +global $g_connection,$g_parameter,$g_user,$cn; if (!defined("DOSSIER"))define ("DOSSIER",25); $_REQUEST['gDossier'] = DOSSIER; $g_connection=new \Database(DOSSIER); +$cn=&$g_connection; $g_parameter = new \Noalyss_Parameter_Folder($g_connection); $_SESSION[SESSION_KEY.'use_name']='unit test'; $_SESSION[SESSION_KEY.'use_first_name']='automatic'; diff --git a/unit-test/include/class/DocumentTest.php b/unit-test/include/class/DocumentTest.php index 294298063..b1f801348 100644 --- a/unit-test/include/class/DocumentTest.php +++ b/unit-test/include/class/DocumentTest.php @@ -222,7 +222,7 @@ class DocumentTest extends TestCase { $document->md_id = $md_id; $cnt_before = $cn->get_value("select count(*) from document"); $tEnv = $_ENV['TMP']; - $_ENV['TMP'] = '/not.exist'; + $_ENV['TMP'] = '/tmp/not.exist'; $this->assertStringContainsString('échoué', $document->generate($array)); $_ENV['TMP'] = $tEnv; } diff --git a/unit-test/include/class/acc_ledger_purchaseTest.php b/unit-test/include/class/acc_ledger_purchaseTest.php index d61c8e42a..c907f90c8 100644 --- a/unit-test/include/class/acc_ledger_purchaseTest.php +++ b/unit-test/include/class/acc_ledger_purchaseTest.php @@ -168,6 +168,10 @@ class Acc_Ledger_PurchaseTest extends TestCase $fiche_def=new Fiche_Def($g_connection,5); // prepare test , clean $fiche_def->RemoveAttribut([20,21,22,50,51,52,53,31]); + $g_connection->exec_sql("delete from jrnx where j_poste=$1", + ['4119999']); + $g_connection->exec_sql("delete from tmp_pcmn where pcm_val=$1", + ['4119999']); } /** * @covers Acc_Ledger_Purchase::verify diff --git a/unit-test/include/class/acc_ledger_saleTest.php b/unit-test/include/class/acc_ledger_saleTest.php index 5a5c1d3d6..89fa7f59a 100644 --- a/unit-test/include/class/acc_ledger_saleTest.php +++ b/unit-test/include/class/acc_ledger_saleTest.php @@ -144,7 +144,7 @@ class Acc_Ledger_SaleTest extends TestCase $g_connection->exec_sql("alter sequence s_jrn_pj2 restart with 40"); // set TVA_RATE by default $g_connection->exec_sql("update tva_rate set tva_poste='41142,45142' where tva_id=5"); - $g_connection->exec_sql("update tva_rate set tva_reverse_account=null where tva_id=5"); + $g_connection->exec_sql("update tva_rate d set tva_reverse_account=null where tva_id=5"); } @@ -156,7 +156,15 @@ class Acc_Ledger_SaleTest extends TestCase $this->object->verify_operation($this->array); $this->assertTrue(TRUE); } - + static function tearDownAfterClass():void + { + + global $g_connection; + $g_connection->exec_sql("delete from jrnx where j_poste=$1", + ['4119999']); + $g_connection->exec_sql("delete from tmp_pcmn where pcm_val=$1", + ['4119999']); + } /** * @covers Acc_Ledger_Sale::insert */ diff --git a/unit-test/include/class/periodeTest.php b/unit-test/include/class/periodeTest.php index 830bbc519..1c4503126 100644 --- a/unit-test/include/class/periodeTest.php +++ b/unit-test/include/class/periodeTest.php @@ -82,12 +82,13 @@ class PeriodeTest extends TestCase return array( [ '01.01.2023' , '31.01.2023','2020','2020.2023','NOK'], [ '01.01.2023' , '31.01.2023','2023','2020.2023','OK'], - [ '01.02.2023' , '28.02.2023','2020','2020.2023','NOK'], [ '01.02.2023' , '28.02.2023','2023','2020.2023','OK'], + [ '01.02.2023' , '28.02.2023','2020','2020.2023','NOK'], [ '01.02.2023' , '28.01.2023','2023','2020.2023','NOK'] ); } + /** * @brief test the trigger comptaproc.check_periode() * @testdox insert - comptaproc.check_periode @@ -99,7 +100,6 @@ class PeriodeTest extends TestCase public function testInsert($p_start,$p_end,$p_exercice,$p_exercice_label,$p_status) { global $g_connection; - $g_connection->exec_sql("delete from parm_periode where p_id > 144"); $obj=new Parm_periode_SQL($g_connection); $obj->set('p_start',$p_start); diff --git a/unit-test/include/lib/http_inputTest.php b/unit-test/include/lib/http_inputTest.php index 2ea183aa7..0c91504b7 100644 --- a/unit-test/include/lib/http_inputTest.php +++ b/unit-test/include/lib/http_inputTest.php @@ -28,7 +28,7 @@ */ use PHPUnit\Framework\TestCase; - +use PHPUnit\Framework\Attributes\DataProvider; require DIRTEST . '/global.php'; /** @@ -44,7 +44,7 @@ class Http_InputTest extends TestCase { * @return array */ - function dataHttpInput() { + static function dataHttpInput() { return array( [ ['value'=>''Test