From 7724e0554af2971acd4114c82b3aff56bbe16b42 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Fri, 2 Feb 2018 13:28:27 +0100 Subject: [PATCH] [FEATURE] System tests for the test and dev environment --- .../Controller/SessionControllerTest.php | 72 +++++++++++++++++++ composer.json | 1 + 2 files changed, 73 insertions(+) create mode 100644 Tests/System/Controller/SessionControllerTest.php diff --git a/Tests/System/Controller/SessionControllerTest.php b/Tests/System/Controller/SessionControllerTest.php new file mode 100644 index 0000000..c5989ba --- /dev/null +++ b/Tests/System/Controller/SessionControllerTest.php @@ -0,0 +1,72 @@ + + */ +class SessionControllerTest extends TestCase +{ + use SymfonyServerTrait; + + /** + * @var Client + */ + private $httpClient = null; + + protected function setUp() + { + $this->httpClient = new Client(['http_errors' => false]); + } + + protected function tearDown() + { + $this->stopSymfonyServer(); + } + + /** + * @return string[][] + */ + public function environmentDataProvider(): array + { + return [ + 'test' => ['test'], + 'dev' => ['dev'], + ]; + } + + /** + * @test + * @param string $environment + * @dataProvider environmentDataProvider + */ + public function postSessionsWithInvalidCredentialsReturnsNotAuthorized(string $environment) + { + $this->startSymfonyServer($environment); + + $loginName = 'john.doe'; + $password = 'a sandwich and a cup of coffee'; + $jsonData = ['login_name' => $loginName, 'password' => $password]; + + $response = $this->httpClient->post( + '/api/v2/sessions', + ['base_uri' => $this->getBaseUrl(), 'body' => \json_encode($jsonData)] + ); + self::assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode()); + self::assertSame( + [ + 'code' => Response::HTTP_UNAUTHORIZED, + 'message' => 'Not authorized', + ], + \json_decode($response->getBody()->getContents(), true) + ); + } +} diff --git a/composer.json b/composer.json index 7987d39..3f16dd3 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "require-dev": { "phpunit/phpunit": "^6.5.0", "phpunit/dbunit": "^3.0.0", + "guzzlehttp/guzzle": "^6.3.0", "squizlabs/php_codesniffer": "^3.2.0", "phpstan/phpstan": "^0.7.0", "nette/caching": "^2.5.0 || ^3.0.0",