Skip to content

Instantly share code, notes, and snippets.

@omnicolor
Created March 11, 2012 15:15
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 omnicolor/2016778 to your computer and use it in GitHub Desktop.
Save omnicolor/2016778 to your computer and use it in GitHub Desktop.
Refactoring static usage
class Foo {
public function addAndSquare($bar, $baz) {
$tmp = $this->add($bar, $baz);
return $this->multiply($tmp, $tmp);
}
protected function add($foo, $bar) {
return Calculator::add($foo, $bar);
}
protected function multiply($foo, $bar) {
return Calculator::multiply($foo, $bar);
}
}
class FooTest
extends PHPUnit_Framework_TestCase {
public function testAddAndSquare() {
$mockFoo = $this->getMock('Foo',
array('add', 'multiply'));
$mockFoo->expects($this->any())
->method('add')
->will($this->returnValue(42));
$mockFoo->expects($this->any())
->method('multiply')
->with($this->equalTo(42),
$this->equalTo(42))
->will($this->returnValue(99));
$this->assertEquals(99,
$mockFoo->addAndSquare(1, 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment