Skip to content

Instantly share code, notes, and snippets.

@fivestar
Created August 9, 2011 03:57
Show Gist options
  • Save fivestar/1133376 to your computer and use it in GitHub Desktop.
Save fivestar/1133376 to your computer and use it in GitHub Desktop.
<?php
class Client
{
public function load($file) {
return $this->getContents($file);
}
protected function getContents($file)
{
return file_get_contents($file);
}
}
<?php
require __DIR__.'/../Client.php';
class ClientTest extends PHPUnit_Framework_TestCase
{
public function testLoad()
{
$client = $this->getClientMock();
$this->assertEquals('Hello, yudoufu', $client->load('http://yudoufu.com/test'));
}
protected function getClientMock()
{
$client = $this->getMock('Client', array('getContents'));
$client->expects($this->any())
->method('getContents')
->will($this->returnValue('Hello, yudoufu'))
;
return $client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment