Skip to content

Tag: mocking

How to test create model service?

I decided to create CreateClassroomService to separte logic in my controller method. I am trying to test this service as part of learning unit testing, but I don’t know how. I don’t know how to mock the classroom object to control what the method should return. Does this mean that creating this se…

PHP Mocking Final Class

I am attempting to mock a php final class but since it is declared final I keep receiving this error: PHPUnit_Framework_Exception: Class “DoctrineORMQuery” is declared “final” and cannot be mocked. Is there anyway to get around this final behavior just for my unit tests without introdu…

PHPUnit: expects method meaning

When I create a new mock I need to call the expects method. What exactly it does? What about its arguments? I can’t find the reason anywhere (I’ve tried docs). I’ve read the sources but I can’t understand it. Answer expects() – Sets how many times you expect a method to be called…

Mock private method with PHPUnit

I have a question about using PHPUnit to mock a private method inside a class. Let me introduce with an example: How can I stub the result of the private method to test the some more code part of the public function. Solved partially reading here Answer Usually you just don’t test or mock the private &a…