vendredi 24 juin 2016

PHPUnit: Mocking objects in 'Wrapper' objects

I don't know whether this works, but I don't find any information how to do this in the documentation or similar blogs:

I want to test my class A with some function calls of class B in their:

class A {

    function foo() {

       B::doSomeThings();
    }
}

For not using the real class B I want to mock this class. If I Unit test my object A I only find the solution to mock this object like:

$mockA = $this->getMockBuilder('\A')->setMethod('foo')->getMock();

$mockA->expects($this->once())->method('foo')->will(...)

Is it possible to only mock the function doSomeThings() in class B

Aucun commentaire:

Enregistrer un commentaire