Created
March 11, 2012 15:15
-
-
Save omnicolor/2016778 to your computer and use it in GitHub Desktop.
Refactoring static usage
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
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