Improve PHPUNIT

This commit is contained in:
sparkyx 2025-10-06 16:38:39 +02:00
parent 4b84ba4879
commit 003fccf58b
7 changed files with 24 additions and 9 deletions

View file

@ -22,11 +22,12 @@
/* /*
* Global variables * Global variables
*/ */
global $g_connection,$g_parameter,$g_user; global $g_connection,$g_parameter,$g_user,$cn;
if (!defined("DOSSIER"))define ("DOSSIER",25); if (!defined("DOSSIER"))define ("DOSSIER",25);
$_REQUEST['gDossier'] = DOSSIER; $_REQUEST['gDossier'] = DOSSIER;
$g_connection=new Database(DOSSIER); $g_connection=new Database(DOSSIER);
$cn=&$g_connection;
$g_parameter = new Noalyss_Parameter_Folder($g_connection); $g_parameter = new Noalyss_Parameter_Folder($g_connection);
$_SESSION[SESSION_KEY.'use_name']='unit test'; $_SESSION[SESSION_KEY.'use_name']='unit test';
$_SESSION[SESSION_KEY.'use_first_name']='automatic'; $_SESSION[SESSION_KEY.'use_first_name']='automatic';

View file

@ -23,11 +23,12 @@
/* /*
* Global variables * Global variables
*/ */
global $g_connection,$g_parameter,$g_user; global $g_connection,$g_parameter,$g_user,$cn;
if (!defined("DOSSIER"))define ("DOSSIER",25); if (!defined("DOSSIER"))define ("DOSSIER",25);
$_REQUEST['gDossier'] = DOSSIER; $_REQUEST['gDossier'] = DOSSIER;
$g_connection=new \Database(DOSSIER); $g_connection=new \Database(DOSSIER);
$cn=&$g_connection;
$g_parameter = new \Noalyss_Parameter_Folder($g_connection); $g_parameter = new \Noalyss_Parameter_Folder($g_connection);
$_SESSION[SESSION_KEY.'use_name']='unit test'; $_SESSION[SESSION_KEY.'use_name']='unit test';
$_SESSION[SESSION_KEY.'use_first_name']='automatic'; $_SESSION[SESSION_KEY.'use_first_name']='automatic';

View file

@ -222,7 +222,7 @@ class DocumentTest extends TestCase {
$document->md_id = $md_id; $document->md_id = $md_id;
$cnt_before = $cn->get_value("select count(*) from document"); $cnt_before = $cn->get_value("select count(*) from document");
$tEnv = $_ENV['TMP']; $tEnv = $_ENV['TMP'];
$_ENV['TMP'] = '/not.exist'; $_ENV['TMP'] = '/tmp/not.exist';
$this->assertStringContainsString('échoué', $document->generate($array)); $this->assertStringContainsString('échoué', $document->generate($array));
$_ENV['TMP'] = $tEnv; $_ENV['TMP'] = $tEnv;
} }

View file

@ -168,6 +168,10 @@ class Acc_Ledger_PurchaseTest extends TestCase
$fiche_def=new Fiche_Def($g_connection,5); $fiche_def=new Fiche_Def($g_connection,5);
// prepare test , clean // prepare test , clean
$fiche_def->RemoveAttribut([20,21,22,50,51,52,53,31]); $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 * @covers Acc_Ledger_Purchase::verify

View file

@ -144,7 +144,7 @@ class Acc_Ledger_SaleTest extends TestCase
$g_connection->exec_sql("alter sequence s_jrn_pj2 restart with 40"); $g_connection->exec_sql("alter sequence s_jrn_pj2 restart with 40");
// set TVA_RATE by default // 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_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->object->verify_operation($this->array);
$this->assertTrue(TRUE); $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 * @covers Acc_Ledger_Sale::insert
*/ */

View file

@ -82,12 +82,13 @@ class PeriodeTest extends TestCase
return array( return array(
[ '01.01.2023' , '31.01.2023','2020','2020.2023','NOK'], [ '01.01.2023' , '31.01.2023','2020','2020.2023','NOK'],
[ '01.01.2023' , '31.01.2023','2023','2020.2023','OK'], [ '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','2023','2020.2023','OK'],
[ '01.02.2023' , '28.02.2023','2020','2020.2023','NOK'],
[ '01.02.2023' , '28.01.2023','2023','2020.2023','NOK'] [ '01.02.2023' , '28.01.2023','2023','2020.2023','NOK']
); );
} }
/** /**
* @brief test the trigger comptaproc.check_periode() * @brief test the trigger comptaproc.check_periode()
* @testdox insert - 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) public function testInsert($p_start,$p_end,$p_exercice,$p_exercice_label,$p_status)
{ {
global $g_connection; global $g_connection;
$g_connection->exec_sql("delete from parm_periode where p_id > 144"); $g_connection->exec_sql("delete from parm_periode where p_id > 144");
$obj=new Parm_periode_SQL($g_connection); $obj=new Parm_periode_SQL($g_connection);
$obj->set('p_start',$p_start); $obj->set('p_start',$p_start);

View file

@ -28,7 +28,7 @@
*/ */
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
require DIRTEST . '/global.php'; require DIRTEST . '/global.php';
/** /**
@ -44,7 +44,7 @@ class Http_InputTest extends TestCase {
* @return array * @return array
*/ */
function dataHttpInput() { static function dataHttpInput() {
return array( return array(
[ ['value'=>'<script'], '<.script'] [ ['value'=>'<script'], '<.script']
, [['value'=>'Test <script'], 'Test <.script'] , [['value'=>'Test <script'], 'Test <.script']
@ -63,6 +63,7 @@ class Http_InputTest extends TestCase {
* @dataProvider dataHttpInput * @dataProvider dataHttpInput
* @global $g_connection * @global $g_connection
*/ */
#[DataProvider('dataHttpInput')]
function testRemoveHarmingString($array,$result) { function testRemoveHarmingString($array,$result) {
$http=new \HttpInput(); $http=new \HttpInput();
// print "value = ".print_r($value,true); // print "value = ".print_r($value,true);