Tag Archives: PHPUnit

How to mock different methods of the same class and how to mock one method with different arguments

I want to mock different methods of the same class and mock one method with different argument values. Using standard PHPUnit.

Mocks in PHPUnit are being created using getMock() method. It belongs to PHPUnit_Framework_TestCase class, that is described in .../PEAR/PHPUnit/Framework/TestCase.php file. Continue reading

How to create mock for a method with reference parameters

While testing PHP we need sometimes to create a mock for a method with reference parameters. I use returnCallback() from PHPUnit framework to to this. returnCallback() will call a function that imitates functionality of the original method. The original method can be either public or protected.
Continue reading