Skip to content

Commit

Permalink
Merge pull request #150 from maurobonfietti/v2.21.0
Browse files Browse the repository at this point in the history
Version 2.21.0
  • Loading branch information
maurobonfietti authored Jun 4, 2023
2 parents c2b28d3 + aaa5461 commit 449276c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<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">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/App/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Controller\User;
use App\Middleware\Auth;

return function ($app) {
return static function ($app) {
$app->get('/', 'App\Controller\DefaultController:getHelp');
$app->get('/status', 'App\Controller\DefaultController:getStatus');
$app->post('/login', \App\Controller\User\Login::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class DefaultController extends BaseController
{
private const API_VERSION = '2.20.0';
private const API_VERSION = '2.21.0';

public function getHelp(Request $request, Response $response): Response
{
Expand Down
9 changes: 7 additions & 2 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ public function getAll(): array
return (array) $statement->fetchAll();
}

public function loginUser(string $email, string $password): User
public function getQueryLoginUser(): string
{
$query = '
return '
SELECT *
FROM `users`
WHERE `email` = :email
ORDER BY `id`
';
}

public function loginUser(string $email, string $password): User
{
$query = $this->getQueryLoginUser();
$statement = $this->database->prepare($query);
$statement->bindParam('email', $email);
$statement->execute();
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,25 @@ public function testLoginUserFailed(): void
$this->assertStringNotContainsString('Bearer', $result);
}

/**
* Test login endpoint with valid user but wrong password.
*/
public function testLoginUserWithWrongPass(): void
{
$response = $this->runApp('POST', '/login', ['email' => '[email protected]', 'password' => 'u2notKnowMe321']);

$result = (string) $response->getBody();

$this->assertEquals(400, $response->getStatusCode());
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type'));
$this->assertStringContainsString('Login failed', $result);
$this->assertStringContainsString('Exception', $result);
$this->assertStringContainsString('error', $result);
$this->assertStringNotContainsString('success', $result);
$this->assertStringNotContainsString('Authorization', $result);
$this->assertStringNotContainsString('Bearer', $result);
}

/**
* Test login endpoint without send required field email.
*/
Expand Down

0 comments on commit 449276c

Please sign in to comment.