I am trying to create a mock object in PHP and PHPUnit. So far, I have this:
$object = $this->getMock('object',
array('set_properties',
'get_events'),
array(),
'object_test',
null);
$object
->expects($this->once())
->method('get_events')
->will($this->returnValue(array()));
$mo = new multiple_object($object);
Ignoring my hideously ambiguous object names for the minute, I understand that what I've done is
- Created a mock object, with 2 methods to configure,
- Configured the 'get_events' method to return a blank array, and
- Dropped the mock into the constructor.
What I'd like to do now is configure the second method, but I can't find anything explaining how to do that. I want to do something like
$object
->expects($this->once())
->method('get_events')
->will($this->returnValue(array()))
->expects($this->once())
->method('set_properties')
->with($this->equalTo(array()))
or some such, but that doesn't work. How should I do that?
Tangentially, does this indicate I've structured my code poorly, if I need to configured more than one method to test?