PHP code example of makeweb / test-server

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

    

makeweb / test-server example snippets





use PHPUnit\Framework\TestCase;
use MakeWeb\TestServer\TestServer;
use Zttp\Zttp;

class MyExampleTest extends TestCase
{
    /** @test */
    public function a_get_request_to_add_route_returns_sum_of_a_and_b_parameters_as_result()
    {
        // Set up how we want the test server to respond
        (new TestServer)->withRoute('get', 'add', function ($request) {
            return response()->json(['result' => (int) $request->a + (int) $request->b]);
        })->start();

        $response = Zttp::get('add', ['a' => 1, 'b' => 2]);

        $this->assertEquals(3, $response->result);
    }
}