jeudi 19 avril 2018

Mock Class that is call from anothe class

So i'm trying to create unit test with mock for elements that have acces with database.

class example1{
   public function getById(){
      //Access to db
   }
}

class example2{
   public function getById(){
      $ex = (new example1())->getById(); 
       //changes ex and returns it. 
   }
}

How can I create a unit test to the getById from class example2 mocking the call to example1.

Can anyone help? Thank you

Aucun commentaire:

Enregistrer un commentaire