Closed esteban-serfe closed 4 months ago
Sorry for the late response - I had gone on a trip for the solar eclipse and just got home.
Does your code happen to start the server with $server->start();
before making requests against it? It's not included in your example.
Probably unrelated small bug, you have '{ "id": ".$id." }'
and '{ "id": '.$id_mu.' }'
. The prior comes out to the string { "id": ".$id." }
which I presume is unintentional. I've fixed it in the following example.
I took your code above and wrapped it in the necessary scaffolding to run it
<?php
use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\Response;
use donatj\MockWebServer\ResponseByMethod;
use donatj\MockWebServer\Responses\NotFoundResponse;
require 'vendor/autoload.php';
$id = '123abc';
$id_mu = '123abc_mu';
$server = new MockWebServer(8086);
$server->setDefaultResponse(new NotFoundResponse);
$response = new ResponseByMethod([
ResponseByMethod::METHOD_POST => new Response(
'{ "id": '.$id.' }',
['Cache-Control' => 'no-cache', 'Content-Type' => 'application/json'],
201
),
ResponseByMethod::METHOD_PUT => new Response(
'{ "id": '.$id_mu.' }',
['Cache-Control' => 'no-cache', 'Content-Type' => 'application/json'],
201
),
]);
$server->setResponseOfPath(
'/api/properties/'.$id.'/sellers',
$response
);
$server->setResponseOfPath(
'/api/properties/'.$id,
$response
);
$server->start();
echo "\n\nPOST\n\n";
$ctx = stream_context_create(['http' => ['method' => 'POST']]);
echo file_get_contents($server->getServerRoot().'/api/properties/'.$id, false, $ctx);
echo "\n\nPUT\n\n";
$ctx = stream_context_create(['http' => ['method' => 'PUT']]);
echo file_get_contents($server->getServerRoot().'/api/properties/'.$id, false, $ctx);
echo "\n\nPOST\n\n";
$ctx = stream_context_create(['http' => ['method' => 'POST']]);
echo file_get_contents($server->getServerRoot().'/api/properties/'.$id.'/sellers', false, $ctx);
echo "\n\nPUT\n\n";
$ctx = stream_context_create(['http' => ['method' => 'PUT']]);
echo file_get_contents($server->getServerRoot().'/api/properties/'.$id.'/sellers', false, $ctx);
running that gives me the following which seems correct to me
Hi @donatj Thanks for looking this up. I was able to have this working in order. I run this inside a Codeception Helper and was having trouble with the correct initialization on the docker setup we have for the project. So is not related to the code issue.
As you mentioned, this is working as expected. We can close this.
I'll open another request separately for an improvement on the debug process later today.
I'm trying to use the url in this following way:
While doing this, the first url works but the second one gives me:
Following the examples on the documentation I'm using: