2
0
forked from Wavyzz/dolibarr

phpunit: use $db instead of $this->savdb

The global variables are stored in $this, and in particular $db is used
through this mean. But $this->savdb is supposed to be the immutable
global state that is stored at the test class instantiation and restored
at the beginning of each test.

For $this->savdb, I don't think any consequences are created by this,
since the object is saved by each test anyway and the $db object is
mostly a query object within a transaction, but future change could use
this to inject a different stateful $db object to trace some behaviour
in the test for instance, so make sure the correct one is used.
This commit is contained in:
Alexandre Janniaux
2023-04-13 20:25:07 +02:00
parent 2635ec9c19
commit b6235c29d0
46 changed files with 198 additions and 194 deletions

View File

@@ -192,10 +192,10 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$conf->facture->dir_output.='/temp';
$localobjectcom=new Commande($this->savdb);
$localobjectcom=new Commande($db);
$localobjectcom->initAsSpecimen();
$localobject=new Facture($this->savdb);
$localobject=new Facture($db);
$localobject->createFromOrder($localobjectcom, $user);
$localobject->date_lim_reglement = dol_now() + 3600 * 24 *30;
@@ -270,7 +270,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$db=$this->savdb;
$conf->fournisseur->facture->dir_output.='/temp';
$localobject=new FactureFournisseur($this->savdb);
$localobject=new FactureFournisseur($db);
$localobject->initAsSpecimen();
// Canelle
@@ -297,7 +297,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$db=$this->savdb;
$conf->commande->dir_output.='/temp';
$localobject=new Commande($this->savdb);
$localobject=new Commande($db);
$localobject->initAsSpecimen();
// Einstein
@@ -325,7 +325,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$db=$this->savdb;
$conf->fournisseur->commande->dir_output.='/temp';
$localobject=new CommandeFournisseur($this->savdb);
$localobject=new CommandeFournisseur($db);
$localobject->initAsSpecimen();
// Muscadet
@@ -352,7 +352,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$db=$this->savdb;
$conf->propal->dir_output.='/temp';
$localobject=new Propal($this->savdb);
$localobject=new Propal($db);
$localobject->initAsSpecimen();
// Azur
@@ -378,7 +378,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$conf->project->dir_output.='/temp';
$localobject=new Project($this->savdb);
$localobject=new Project($db);
$localobject->initAsSpecimen();
// Baleine
@@ -405,7 +405,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$db=$this->savdb;
$conf->ficheinter->dir_output.='/temp';
$localobject=new Fichinter($this->savdb);
$localobject=new Fichinter($db);
$localobject->initAsSpecimen();
// Soleil
@@ -432,7 +432,7 @@ class BuildDocTest extends PHPUnit\Framework\TestCase
$db=$this->savdb;
$conf->expedition->dir_output.='/temp';
$localobject=new Expedition($this->savdb);
$localobject=new Expedition($db);
$localobject->initAsSpecimen();
// Merou