You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
2.1 KiB
111 lines
2.1 KiB
<?php
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
|
|
|
|
class ClientRequestBuilder
|
|
{
|
|
protected KernelBrowser $client;
|
|
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
private $method;
|
|
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
private $uri;
|
|
|
|
/**
|
|
*
|
|
* @var array
|
|
*/
|
|
private $parameters;
|
|
|
|
/**
|
|
*
|
|
* @var array
|
|
*/
|
|
private $server;
|
|
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
private $acceptType;
|
|
|
|
public function __construct(KernelBrowser $client)
|
|
{
|
|
$this->client = $client;
|
|
$this->parameters = [];
|
|
$this->server = [];
|
|
$this->acceptType = 'application/json';
|
|
}
|
|
|
|
public static function create(KernelBrowser $client): ClientRequestBuilder
|
|
{
|
|
return new ClientRequestBuilder($client);
|
|
}
|
|
|
|
public function setMethod(string $method): self
|
|
{
|
|
$this->method = $method;
|
|
return $this;
|
|
}
|
|
|
|
public function setUri(string $uri): self
|
|
{
|
|
$this->uri = $uri;
|
|
return $this;
|
|
}
|
|
|
|
public function addParameter(string $key, $value): self
|
|
{
|
|
$this->parameters[$key] = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function setParameters(array $parameters): self
|
|
{
|
|
$this->parameters = $parameters;
|
|
return $this;
|
|
}
|
|
|
|
public function addServerParameter(string $key, $value): self
|
|
{
|
|
$this->server[$key] = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function setServerParameters(array $parameters): self
|
|
{
|
|
$this->server = $parameters;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param string $acceptType
|
|
*/
|
|
public function setAcceptType(string $acceptType): self
|
|
{
|
|
$this->acceptType = $acceptType;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Executes the request and returns the crawler.
|
|
*/
|
|
public function request(): Crawler
|
|
{
|
|
$this->server['HTTP_ACCEPT'] = $this->acceptType;
|
|
return $this->client->request($this->method, $this->uri, $this->parameters, [], $this->server);
|
|
}
|
|
}
|
|
|