From d042a3b84a461055c5cf164e8aa1ea188e81eac6 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 1 Sep 2020 16:55:40 +0200 Subject: [PATCH] Fix namespace Improved testing methods --- bootstrap/app.php | 4 ++-- tests/Feature/LoginControllerTest.php | 4 ++-- tests/TestCase.php | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index d25d397..8200783 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,7 +1,7 @@ client->request('GET', '/login'); - $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + $response = $this->get('/login'); + $this->assertSame(200, $response->getStatusCode()); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9aa2a34..002928c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase @@ -16,4 +17,26 @@ abstract class TestCase extends BaseTestCase $this->client = new Client(); } + + /** + * @param string $uri + * @param array $parameters + * @return Response|object + */ + public function get(string $uri, array $parameters = []) + { + $this->client->request('GET', $uri, $parameters); + return $this->client->getResponse(); + } + + /** + * @param string $uri + * @param array $parameters + * @return Response|object + */ + public function post(string $uri, array $parameters = []) + { + $this->client->request('POST', $uri, $parameters); + return $this->client->getResponse(); + } }