Skip to content

Commit 449276c

Browse files
Merge pull request #150 from maurobonfietti/v2.21.0
Version 2.21.0
2 parents c2b28d3 + aaa5461 commit 449276c

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php">
33
<coverage includeUncoveredFiles="true">
44
<include>
55
<directory suffix=".php">src</directory>

src/App/Routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use App\Controller\User;
88
use App\Middleware\Auth;
99

10-
return function ($app) {
10+
return static function ($app) {
1111
$app->get('/', 'App\Controller\DefaultController:getHelp');
1212
$app->get('/status', 'App\Controller\DefaultController:getStatus');
1313
$app->post('/login', \App\Controller\User\Login::class);

src/Controller/DefaultController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class DefaultController extends BaseController
1111
{
12-
private const API_VERSION = '2.20.0';
12+
private const API_VERSION = '2.21.0';
1313

1414
public function getHelp(Request $request, Response $response): Response
1515
{

src/Repository/UserRepository.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ public function getAll(): array
8787
return (array) $statement->fetchAll();
8888
}
8989

90-
public function loginUser(string $email, string $password): User
90+
public function getQueryLoginUser(): string
9191
{
92-
$query = '
92+
return '
9393
SELECT *
9494
FROM `users`
9595
WHERE `email` = :email
9696
ORDER BY `id`
9797
';
98+
}
99+
100+
public function loginUser(string $email, string $password): User
101+
{
102+
$query = $this->getQueryLoginUser();
98103
$statement = $this->database->prepare($query);
99104
$statement->bindParam('email', $email);
100105
$statement->execute();

tests/integration/UserTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,25 @@ public function testLoginUserFailed(): void
364364
$this->assertStringNotContainsString('Bearer', $result);
365365
}
366366

367+
/**
368+
* Test login endpoint with valid user but wrong password.
369+
*/
370+
public function testLoginUserWithWrongPass(): void
371+
{
372+
$response = $this->runApp('POST', '/login', ['email' => '[email protected]', 'password' => 'u2notKnowMe321']);
373+
374+
$result = (string) $response->getBody();
375+
376+
$this->assertEquals(400, $response->getStatusCode());
377+
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type'));
378+
$this->assertStringContainsString('Login failed', $result);
379+
$this->assertStringContainsString('Exception', $result);
380+
$this->assertStringContainsString('error', $result);
381+
$this->assertStringNotContainsString('success', $result);
382+
$this->assertStringNotContainsString('Authorization', $result);
383+
$this->assertStringNotContainsString('Bearer', $result);
384+
}
385+
367386
/**
368387
* Test login endpoint without send required field email.
369388
*/

0 commit comments

Comments
 (0)