PHP code example of mnapoli / phpunit-easymock

1. Go to this page and download the library: Download mnapoli/phpunit-easymock library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mnapoli / phpunit-easymock example snippets


class MyTest extends \PHPUnit\Framework\TestCase
{
    use \EasyMock\EasyMock;

    // ...
}

$mock = $this->createMock('My\Class');

$mock->expect($this->any())
    ->method('sayHello')
    ->willReturn('Hello');

$mock = $this->easyMock('My\Class', [
    'sayHello' => 'Hello',
]);

$mock = $this->easySpy('My\Class', [
    'sayHello' => 'Hello',
]);

$mock = $this->easyMock('My\Class', [
    'sayHello' => 'Hello',
]);

$mock = $this->easyMock('My\Class', [
    'sayHello' => function ($name) {
        return 'Hello ' . $name;
    },
]);

$mock = $this->easyMock('My\Class', [
    'sayHello' => new \RuntimeException('Whoops'),
]);

$mock = $this->easyMock('My\Class');

$mock = $this->easyMock($mock, [
    'sayHello' => 'Hello',
]);

$mock = $this->easyMock('My\Class', [
    'sayHello' => 'hello',
]);

$mock->expects($this->once())
    ->method('sayGoodbye')
    ->willReturn('Goodbye');