Skip to content

Instantly share code, notes, and snippets.

@giorgiosironi
Created July 5, 2011 14:21
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 giorgiosironi/1064921 to your computer and use it in GitHub Desktop.
Save giorgiosironi/1064921 to your computer and use it in GitHub Desktop.
Non existent methods cannot be mocked
<?php
class MyMethodOfficiallyDoesNotExist
{
public function __call($method, $args) {
return true;
}
}
class MockingNotExistingMethodsTest extends PHPUnit_Framework_TestCase
{
public function testANonExistentMethod()
{
$original = new MyMethodOfficiallyDoesNotExist();
$this->assertTrue($original->doesNotExist());
$mock = $this->getMock('MyMethodOfficiallyDoesNotExist');
$mock->expects($this->any())
->method('doesNotExist')
->will($this->returnValue(false));
$this->assertFalse($mock->doesNotExist());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment