File tree Expand file tree Collapse file tree 5 files changed +29
-5
lines changed
Expand file tree Collapse file tree 5 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 77use App \Controller \User ;
88use 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);
Original file line number Diff line number Diff line change 99
1010final 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 {
Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments