Skip to content

Commit cfa08d6

Browse files
oliverkleeSam Tuke
authored andcommitted
[FEATURE] System tests for the test and dev environment (#81)
1 parent 5a8ace4 commit cfa08d6

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PhpList\RestBundle\Tests\System\Controller;
5+
6+
use GuzzleHttp\Client;
7+
use PhpList\PhpList4\TestingSupport\Traits\SymfonyServerTrait;
8+
use PHPUnit\Framework\TestCase;
9+
use Symfony\Component\HttpFoundation\Response;
10+
11+
/**
12+
* Testcase.
13+
*
14+
* @author Oliver Klee <[email protected]>
15+
*/
16+
class SessionControllerTest extends TestCase
17+
{
18+
use SymfonyServerTrait;
19+
20+
/**
21+
* @var Client
22+
*/
23+
private $httpClient = null;
24+
25+
protected function setUp()
26+
{
27+
$this->httpClient = new Client(['http_errors' => false]);
28+
}
29+
30+
protected function tearDown()
31+
{
32+
$this->stopSymfonyServer();
33+
}
34+
35+
/**
36+
* @return string[][]
37+
*/
38+
public function environmentDataProvider(): array
39+
{
40+
return [
41+
'test' => ['test'],
42+
'dev' => ['dev'],
43+
];
44+
}
45+
46+
/**
47+
* @test
48+
* @param string $environment
49+
* @dataProvider environmentDataProvider
50+
*/
51+
public function postSessionsWithInvalidCredentialsReturnsNotAuthorized(string $environment)
52+
{
53+
$this->startSymfonyServer($environment);
54+
55+
$loginName = 'john.doe';
56+
$password = 'a sandwich and a cup of coffee';
57+
$jsonData = ['login_name' => $loginName, 'password' => $password];
58+
59+
$response = $this->httpClient->post(
60+
'/api/v2/sessions',
61+
['base_uri' => $this->getBaseUrl(), 'body' => \json_encode($jsonData)]
62+
);
63+
self::assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
64+
self::assertSame(
65+
[
66+
'code' => Response::HTTP_UNAUTHORIZED,
67+
'message' => 'Not authorized',
68+
],
69+
\json_decode($response->getBody()->getContents(), true)
70+
);
71+
}
72+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"require-dev": {
3636
"phpunit/phpunit": "^6.5.0",
3737
"phpunit/dbunit": "^3.0.0",
38+
"guzzlehttp/guzzle": "^6.3.0",
3839
"squizlabs/php_codesniffer": "^3.2.0",
3940
"phpstan/phpstan": "^0.7.0",
4041
"nette/caching": "^2.5.0 || ^3.0.0",

0 commit comments

Comments
 (0)