Created
March 5, 2012 19:48
-
-
Save christeredvartsen/1980593 to your computer and use it in GitHub Desktop.
Issue with the at matcher in PHPUnit
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 | |
class Bar { | |
public function run() { | |
// do something | |
} | |
public function exec() { | |
// do something | |
} | |
} | |
class Foo { | |
private $bar; | |
public function __construct(Bar $bar) { | |
$this->bar = $bar; | |
} | |
public function runBar() { | |
var_dump($this->bar->run()); | |
var_dump($this->bar->run()); | |
var_dump($this->bar->run()); | |
} | |
public function execBar() { | |
var_dump($this->bar->exec()); | |
} | |
} | |
class FooTest extends PHPUnit_Framework_TestCase { | |
public function testFoo() { | |
$bar = $this->getMock('Bar'); | |
$bar->expects($this->any())->method('exec')->will($this->returnValue('exec')); | |
$bar->expects($this->at(0))->method('run')->will($this->returnValue('first run')); | |
$bar->expects($this->at(1))->method('run')->will($this->returnValue('second run')); | |
$bar->expects($this->at(2))->method('run')->will($this->returnValue('third run')); | |
$foo = new Foo($bar); | |
$foo->execBar(); | |
$foo->runBar(); | |
} | |
} | |
// Output: | |
// string(4) "exec" | |
// string(10) "second run" | |
// string(9) "third run" | |
// NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment