mardi 11 octobre 2016

How can I mock a method of an object and return one of its parameters in PHP SimpleTest framework?

Suppose you want to mock a simple method of a class:

Mock::generatePartial(MyClass::class, false, ['aMethod']);
$this->aMock = new MockMyClass();
$this->aMock->returns('aMethod', $param2, [$param1, $param2, $param3]);

And every time the code makes a call to "aMethod" with the corresponding parameters, the mock object returns the second parameter passed.

In fact, you do not care what $param1 and $param2 are. The only thing you want is a return value exactly equal to the $param2.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire