Mock: how is passive partial layout different from default layout?

In the last paragraphs of this (large) quick link to Mockery, the author explains some behavior modifiers for the layout that are not standard but might be useful. These include challenge makePartial()

and challenge shouldDeferMissing()

.

How do they differ from the default behavior? When you mock ( Mockery::mock('myClass')

) and don't add any method expectations, all method calls go to the parent (like MyClass) as far as I can see ...

Here's the last section of the Mockery quick reference.

\ mock :: mock ('MyClass') -> makePartial ()

and

\ mock :: mock ('MyClass') -> shouldDeferMissing ()

Known as passive partial layout (not to be confused with real partial layout objects discussed later), this form of layout object will defer all methods not expected by the parent layout class, i.e. MyClass. Whereas the previous one should return an IgnoreMissing () null event, this behavior simply calls the parent matching method.

+3


source to share


1 answer


  • Fully qualified objects require all method calls to be expected
  • Real mock partials will only mock the specified methods and you cannot set expectations for non-fake methods. If you did not specify a method when creating the layout, it will defer all calls to that method to the parent class.
  • Passive partial mocks defer method calls without waiting for the parent mock class.


The difference between the last two is that for passive partial mocks, you don't need to specify which methods you are going to mock before setting the wait. When you set an expectation, it will create a bullying method for you.

+4


source







All Articles