Created
January 3, 2017 07:15
-
-
Save christeredvartsen/8dccfc2d3e219d9db7d2df60269c1931 to your computer and use it in GitHub Desktop.
Use a callback for return values with a mock 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 SomeClass { public function someMethod() {} } | |
class SomeClassTest extends PHPUnit_Framework_TestCase { | |
public function testSomeMethod() { | |
$someValue = ' ... '; | |
$mock = $this->createMock('SomeClass'); | |
$mock | |
->expects($this->once()) | |
->method('someMethod') | |
->will($this->returnCallback(function($arg1, $arg2) use ($someValue) { | |
// ... | |
})); | |
$mock->someMethod('foo', 'bar'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment