PHP code example of jobcloud / jobcloud-http-mock-server
1. Go to this page and download the library: Download jobcloud/jobcloud-http-mock-server 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/ */
jobcloud / jobcloud-http-mock-server example snippets
declare(strict_types=1);
namespace MyProject\Tests;
use Jobcloud\HttpMockServer\HttpMockServer;
use Jobcloud\HttpMockServer\Response;
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
public function testSomthingWithHttpCalls()
{
$httpMockServer = new HttpMockServer();
$httpMockServer->run(8080, [
Response::create()
->withStatus(200)
->withHeader('Content-Type', 'application/json')
->withBody('{"id":1, "email":"[email protected]"}'),
]);
file_get_contents(
'http://localhost:8080/',
false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode(['email' => '[email protected]']),
],
])
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.