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

@@ -150,7 +150,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new AdherentType($this->savdb);
$localobject=new AdherentType($db);
$localobject->statut=1;
$localobject->label='Adherent type test';
$localobject->subscription=1;
@@ -181,7 +181,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Adherent($this->savdb);
$localobject=new Adherent($db);
$localobject->initAsSpecimen();
$localobject->typeid=$fk_adherent_type;
$result=$localobject->create($user);
@@ -211,7 +211,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Adherent($this->savdb);
$localobject=new Adherent($db);
$result=$localobject->fetch($id);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
@@ -235,7 +235,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$newobject = new Adherent($this->savdb);
$newobject = new Adherent($db);
$result = $newobject->fetch_login($localobject->login);
$this->assertEquals($newobject, $localobject);
@@ -291,7 +291,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
$newobject=new Adherent($this->savdb);
$newobject=new Adherent($db);
$result=$newobject->fetch($localobject->id);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
@@ -579,7 +579,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$localobjectat=new AdherentType($this->savdb);
$localobjectat=new AdherentType($db);
$result=$localobjectat->fetch($localobject->typeid);
$result=$localobjectat->delete();
print __METHOD__." result=".$result."\n";