Created
June 15, 2011 21:33
-
-
Save s0enke/1028181 to your computer and use it in GitHub Desktop.
Stubbing protected methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!