A minimal http mock server.
- php: ^7.1|^8.0
- react/event-loop: >=0.4,
- react/http: ^0.8.4,
- symfony/process: ^3.4|^4.2
Through Composer as jobcloud/jobcloud-http-mock-server.
<?php
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]']),
                ],
            ])
        );
    }
}Jobcloud AG 2019

