My code access only hard coded ID (/api/user/{id}). But I want it works with dynamic value (for example: uuid).
/**
* @When I send a :http request to :url
*
* @param $http
* @param $url
*/
public function iSendARequestTo($http, $url)
{
$url = $this->attachQueries($url);
if ($this->isUrlContainsRuntimeParameters($url)) {
$url = $this->mergeRuntimeParametersValues($url);
}
$this->client->request(
$http,
$url,
$this->parameters,
[],
$this->headers,
$this->rawData
);
$this->response = $this->client->getResponse();
}
Extra Functions:
private function attachQueries($url)
{
foreach ($this->queries as $key => $value) {
if(strpos($url,'?') !== false) {
$url .= '&' .$key. '=' .$value;
} else {
$url .= '?' .$key. '=' .$value;
}
}
return $url;
}
private function isUrlContainsRuntimeParameters($url)
{
preg_match(self::RUNTIME_PARAMETER_PATTERN, $url, $matches);
return !empty($matches);
}
private function mergeRuntimeParametersValues($parameter)
{
preg_match(self::RUNTIME_PARAMETER_PATTERN, $parameter, $matches);
return empty($matches)
? $parameter
: preg_replace(self::RUNTIME_PARAMETER_PATTERN, $this->runtimeParameters[$matches[1]], $parameter);
}
I want to rebuild method "iSendARequestTo()" make it works with dynamic Doctrine Values (e.g. uuid)