How to mock dependency injection with phpunit? How to mock dependency injection with phpunit? symfony symfony

How to mock dependency injection with phpunit?


You have to use the real classname, otherwise PHPunit will just create a class named Router (note: this is not the expected Symfony\Component\Routing\Router):

     // don't need it here, Swift_Mailer is in the global scope    $mailer = $this->getMockBuilder('Swift_Mailer')        ->disableOriginalConstructor()        ->getMock();    $router = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\Router')        ->disableOriginalConstructor()        ->getMock();    $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')        ->disableOriginalConstructor()        ->getMock();    $emailMan = $this->getMockBuilder('Full\Namespace\To\EmailManager')        ->disableOriginalConstructor()        ->getMock();    $emailReminderMan = $this->getMockBuilder('Full\Namespace\To\EmailReminderManager')        ->disableOriginalConstructor()        ->getMock();