I just started with unit testing in CakePHP (yay!) And ran into the following problem. Hope someone can help me :-)
Situation
My model uses behavior to send changes to the API after saving locally. I would like to fake all the calls made in the API during the test (those will be checked separately) in order to save the load on the API server and, more importantly, not really save the changes :-)
I am using CakePHP 2.4.1.
What i tried
- Read the docs. The manual shows how to do this for components and helpers, but not for behavior.
- Google What I found:
The code from the article reads:
$provider = $this->getMock('OurProvider', array('getInfo')); $provider->expects($this->any()) ->method('getInfo') ->will($this->returnValue('200'));
This may be the wrong direction, but I think this may be a good start.
What I want
Effective: a code snippet to demonstrate how to mock the behavior in the CakePHP model for unit testing purposes.
Perhaps this question will lead to the addition of CakePHP's guide as an added bonus as well, as I feel it is missing there.
Thanks in advance for this!
Update (2013-11-07)
I found this related question that should answer this question (partially). No need to mock the API, instead I can create a behavior test that the model will use.
I'm trying to figure out what this BehaviorTest should look like.
source share