I had the same problem and found a solution in SimpleTest test cases:
From mock_objects_test.php:
class ClassWithSpecialMethods { function __get($name) { } function __set($name, $value) { } function __isset($name) { } function __unset($name) { } function __call($method, $arguments) { } function __toString() { } } Mock::generate('ClassWithSpecialMethods');
... snip ...
function testReturnFromSpecialAccessor() { $mock = new MockClassWithSpecialMethods(); $mock->setReturnValue('__get', '1st Return', array('first')); $mock->setReturnValue('__get', '2nd Return', array('second')); $this->assertEqual($mock->first, '1st Return'); $this->assertEqual($mock->second, '2nd Return'); } function testcanExpectTheSettingOfValue() { $mock = new MockClassWithSpecialMethods(); $mock->expectOnce('__set', array('a', 'A')); $mock->a = 'A'; }
A bit clumsy, but it works. On the other hand, I think you better avoid them ... the big corporate system I'm working on uses them a lot, and it's a nightmare to understand / visualize / debug / do something with!
penfold
source share