From e05f13454c66ecf960a3bfd9529f4f409137e524 Mon Sep 17 00:00:00 2001 From: hecht Date: Thu, 15 Nov 2018 22:45:59 +0100 Subject: [PATCH] Added some stubs for unit testing. --- tests/ClientRequestBuilder.php | 12 --- tests/Controller/ClientRequestBuilder.php | 114 ++++++++++++++++++++++ tests/Controller/RestTestBase.php | 20 ++++ 3 files changed, 134 insertions(+), 12 deletions(-) delete mode 100644 tests/ClientRequestBuilder.php create mode 100644 tests/Controller/ClientRequestBuilder.php create mode 100644 tests/Controller/RestTestBase.php diff --git a/tests/ClientRequestBuilder.php b/tests/ClientRequestBuilder.php deleted file mode 100644 index ff64cf4..0000000 --- a/tests/ClientRequestBuilder.php +++ /dev/null @@ -1,12 +0,0 @@ -client = $client; + $this->parameters = []; + $this->server = []; + $this->acceptType = 'application/json'; + } + + public static function create(Client $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); + } +} + diff --git a/tests/Controller/RestTestBase.php b/tests/Controller/RestTestBase.php new file mode 100644 index 0000000..2a70164 --- /dev/null +++ b/tests/Controller/RestTestBase.php @@ -0,0 +1,20 @@ +client); + $builder->setAcceptType($acceptType); + return $builder; + } +} \ No newline at end of file