PHP code example of holgerk / mockery-simple-mock

1. Go to this page and download the library: Download holgerk/mockery-simple-mock 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/ */

    

holgerk / mockery-simple-mock example snippets


use function Holgerk\MockerySimpleMock\simpleMock;

$mock = simpleMock(MyService::class);

$mock = simpleMock(MyService::class, $capturedCalls);

$mock->greet('Alice', 42);

// $capturedCalls['greet'] === [['name' => 'Alice', 'age' => 42]]

$mock->greet('Alice', 1);
$mock->greet('Bob', 2);

// $capturedCalls['greet'] === [
//     ['name' => 'Alice', 'age' => 1],
//     ['name' => 'Bob', 'age' => 2],
// ]

$mock = simpleMock(MyService::class, $capturedCalls);

$mock->greet('Alice', 42);
$mock->greet('Bob', 7);

assertEquals([
    ['name' => 'Alice', 'age' => 42],
    ['name' => 'Bob',   'age' => 7],
], $capturedCalls['greet']);

$mock = simpleMock(MyService::class, $capturedCalls, [
    'greet' => 'Hello, Alice!',
]);

$result = $mock->greet('Alice', 42); // 'Hello, Alice!'