PHP code example of citruslab / mokkd

1. Go to this page and download the library: Download citruslab/mokkd 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/ */

    

citruslab / mokkd example snippets


$time = Mokkd::func("time")
    ->returning(0);

$time = Mokkd::func("time")
    ->returningFrom([0, 1, 2])

$getEnv = Mokkd::func("getenv"
    ->returningMappedValueFrom(
        [
            "host" => "example.com",
            "secret" => "fake-secret"
        ],
        0,
    )

$time = Mokkd::func("time")
    ->returningUsing(static function(): int {
        static $count = 0;
        return 60 * $count++;
    })

$time = Mokkd::func("time")
    ->times(3)
    ->returning(0);

$time = Mokkd::func("time")
    ->once()
    ->returning(0);

$time = Mokkd::func("time")
    ->twice()
    ->returning(0);

$getEnv = Mokkd::func("getenv")
    ->expects("host")
    ->returning("example.com")

$getEnv = Mokkd::func("substr")
    ->expects(Mokkd::isString(), 0, Mokkd::isIntGreaterThan(2))
    ->returning("leftmost")

$getEnv = Mokkd::func("getenv")
    ->expects("host")
    ->returning("example.com")
    ->withoutBlocking()