Helpers to build PHPUnit mock objects easily.
This library is not a mocking library. It's just a few helpers to write the most common mocks more easily.
It doesn't reinvent anything and is not intended to cover every use case: only the most common ones.
$ composer require --dev mnapoli/phpunit-easymockHere is what a very common PHPUnit mock looks like:
// All these parameters to avoid calling the constructor $mock = $this->getMock('My\Class', array(), array(), '', false); $mock->expect($this->any()) ->method('sayHello') ->willReturn('Hello');Yuck!
Here is how to write it with EasyMock:
$mock = EasyMock::mock('My\Class', array( 'sayHello' => 'Hello', ));You can mock methods so that they return values:
$mock = EasyMock::mock('My\Class', array( 'sayHello' => 'Hello', ));Or so that they use a callback:
$mock = EasyMock::mock('My\Class', array( 'sayHello' => function ($name) { return 'Hello ' . $name; }, ));If you want to use assertions or other PHPUnit features, just do it:
$mock = EasyMock::mock('My\Class', array( 'sayHello' => 'hello', )); $mock->expects($this->once()) ->method('sayGoodbye') ->willReturn('Goodbye');Mocks are plain PHPUnit mocks, nothing special here.
See the CONTRIBUTING file.
Released under the MIT license.

