PHP code example of neur0toxine / pock

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

    

neur0toxine / pock example snippets


use Nyholm\Psr7\Factory\Psr17Factory;
use Pock\Enum\RequestMethod;
use Pock\PockBuilder;

$pock = new PockBuilder();
$pock->matchMethod(RequestMethod::GET)
    ->matchUri('https://api.example.com/users/42')
    ->reply(200)
    ->withHeader('Content-Type', 'application/json')
    ->withJson(['id' => 42, 'name' => 'Jane']);

$factory = new Psr17Factory();
$request = $factory->createRequest('GET', 'https://api.example.com/users/42');
$response = $pock->getClient()->sendRequest($request);

assert(200 === $response->getStatusCode());
assert(['id' => 42, 'name' => 'Jane'] === json_decode((string) $response->getBody(), true));