PHP code example of jfalque / http-mock

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

    

jfalque / http-mock example snippets




use Jfalque\HttpMock\Server;

$server = (new Server())
    ->whenUri('http://foo')
        ->return($foo = new Response())
    ->end()
    ->whenUri('http://bar')
        ->return($bar = new Response())
    ->end()
;

$response = $server->handle(new Request('http://foo')); // $foo
$response = $server->handle(new Request('http://bar')); // $bar
$response = $server->handle(new Request('http://baz')); // null