0

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

1 Answer 1

1

There are some workarounds

http://miljar.github.io/blog/2014/01/29/phpunit-testing-static-calls/

or you can move to other method in A function and like

class A {

    function foo() {

     $this->doSomeThings();
    }

    function doSomeThings() {
       B::doSomeThings();
    }
}

and mock doSomeThings() function in A class

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.