title: PHPUnit: Mock methods of existing object
body: <p>PHPUnit's <code>getMock($classname, $mockmethods)</code> creates a new object based on the given class name and lets me change/test the behavior of the methods I specified.</p>
  
  <p>I long for something different; it's changing the behavior of methods of an existing object - without constructing a new object.</p>
  
  <p>Is that possible? If yes, how?</p>
  
  <hr>
  
  <p>When thinking about the problem I came to the conclusion that it would be possible by serializing the object, changing the serialized string to let the object be instance of a <em>new class</em> that extends the old class plus the mocked methods.
  I'd like some code for that - or maybe there is such code already somewhere.</p>
  
  <hr>
  
  <p>While it would certainly be possible to create the to-be-mocked object again, it's just too complicated to do it in my test. Thus I don't want to do that if I don't really really really have to. It's a TYPO3 TSFE instance, and setting that up once in the bootstrapping process is hard enough already.</p>