Skip to content

Instantly share code, notes, and snippets.

@gskema
Last active April 14, 2017 08:59
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 gskema/95ddf38b6187881e43b42128b8806079 to your computer and use it in GitHub Desktop.
Save gskema/95ddf38b6187881e43b42128b8806079 to your computer and use it in GitHub Desktop.
PHPUnit setMethods explained by an example
<?php
class Banana
{
public function a()
{
return 1;
}
public function b()
{
return 2;
}
}
$this->getMockBuilder(Banana::class)->getMock(); // a: null, b: null
$this->getMockBuilder(Banana::class)->setMethods([])->getMock(); // a: null, b: null
$this->getMockBuilder(Banana::class)->setMethods(null)->getMock(); // a: 1, b: 2
$this->getMockBuilder(Banana::class)->setMethods(['a'])->getMock(); // a: null, b: 2
$this->getMockBuilder(Banana::class)->setMethods(['b'])->getMock(); // a: 1, b: null
$this->getMockBuilder(Banana::class)->setMethods(['a', 'b'])->getMock(); // a: null, b: null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment