Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save and1truong/369b929fd1d67753b4b5 to your computer and use it in GitHub Desktop.
Save and1truong/369b929fd1d67753b4b5 to your computer and use it in GitHub Desktop.
<?php
use PHPUnit_Framework_MockObject_MockObject as Mock;
class FooTest extends PHPUnit_Framework_Testcase {
public function getFoo() {
$service = $this->getService(function(Mock $service) {
$service->expects($this->once())->method('foo');
});
$service->doFoo();
}
public function getBar() {
$service = $this->getService(function(Mock $service) {
$service->expects($this->at(2))->method('foo');
});
$this->doBar();
}
public function getService(callable $callback) {
$service = $this->getMock(MyService::class);
$callback($service);
return $service;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment