Skip to content

Instantly share code, notes, and snippets.

@s0enke
Created June 15, 2011 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s0enke/1028181 to your computer and use it in GitHub Desktop.
Save s0enke/1028181 to your computer and use it in GitHub Desktop.
Stubbing protected methods
<?php
require 'PHPUnit/Framework/TestCase.php';
class CouchDB
{
public function doGeloet()
{
return $this->makeRequest();
}
protected function makeRequest()
{
return 'doing external shit';
}
}
class CouchDBTest extends PHPUnit_Framework_TestCase
{
public function testYourMum()
{
$couch = $this->getMock('CouchDB', array('makeRequest'));
$couch->expects($this->any())->method('makeRequest')->will($this->returnValue('Stubbed!'));
$this->assertEquals('Stubbed!', $couch->doGeloet());
}
}
@till
Copy link

till commented Jun 15, 2011

Yeah, working now. I probably didn't have getMock('foo', array('protectedMethod')). That's the only thing I can think of. Though I'm sure I tried that before. ;-(

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment