jobcloud/jobcloud-http-mock-server

This package is abandoned and no longer maintained. No replacement package was suggested.

A minimal http mock server.

3.0.0 2022-10-20 08:47 UTC

This package is auto-updated.

Last update: 2023-01-06 12:09:35 UTC


README

CircleCI Total Downloads Monthly Downloads Latest Stable Version Latest Unstable Version

Description

A minimal http mock server.

Requirements

  • php: ^7.1|^8.0
  • react/event-loop: >=0.4,
  • react/http: ^0.8.4,
  • symfony/process: ^3.4|^4.2

Installation

Through Composer as jobcloud/jobcloud-http-mock-server.

Usage

<?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":"john.doe@jobcloud.ch"}'),
        ]);

        file_get_contents(
            'http://localhost:8080/',
            false,
            stream_context_create([
                'http' => [
                    'method' => 'POST',
                    'header' => 'Content-Type: application/json',
                    'content' => json_encode(['email' => 'john.doe@jobcloud.ch']),
                ],
            ])
        );
    }
}

Copyright

Jobcloud AG 2019