Skip to content

[FEATURE] System tests for the test and dev environment #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Tests/System/Controller/SessionControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);

namespace PhpList\RestBundle\Tests\System\Controller;

use GuzzleHttp\Client;
use PhpList\PhpList4\TestingSupport\Traits\SymfonyServerTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;

/**
* Testcase.
*
* @author Oliver Klee <[email protected]>
*/
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)
);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down