Skip to content

jobcloud/jobcloud-http-mock-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jobcloud-http-mock-server

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":"[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]']),
                ],
            ])
        );
    }
}

Copyright

Jobcloud AG 2019