Skip to content
Advertisement

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 service was not a good idea because I

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 introducing any new frameworks? Answer Since you mentioned you don’t want to use any other

Mockery: how does a passive partial mock differ from the default mock?

In the very last paragraphs of this (great) quick reference to Mockery, the author explains some behaviour modifiers for a mock which are not default, but may be useful. These include the makePartial() call and the shouldDeferMissing() call. How do these differ from the default behaviour? When you create a mock (Mockery::mock(‘myClass’)), and don’t add any method expectations, all method

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: If you know, that method is 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 & protected methods directy.

Advertisement