donatj / mock-webserver

Simple mock web server in PHP for unit testing.
MIT License
131 stars 21 forks source link

Feature: Mock a dynamic url #23

Open didslm opened 4 years ago

didslm commented 4 years ago

What if we could mock an endpoint like this /endpoint/product/* So then it would not matter what parameter we send in the * we would get the same response.

<?php

use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\RequestInfo;
use donatj\MockWebServer\Response;

require 'vendor/autoload.php';

$server = new MockWebServer();
$server->start();

$url     = $server->setResponseOfPath("/api/endpoint/product/*", new Response('abc'));
 //request '/api/endpoint/product/1' will result in: abc
donatj commented 4 years ago

I think this would be a useful feature to have.

Off the top of my head I'm not sure a great way to implement it but I will certainly look into it.

itsjavi commented 3 years ago

It would be very helpful. Having HTTP 200 responses when something is not mocked is not ideal.

donatj commented 3 months ago

@ellipsis-dev can you give this a shot?