-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e381d14
commit 2ca8100
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace HyperfTest\Cases; | ||
|
||
use Hyperf\Testing\TestCase; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class UserTest extends TestCase | ||
{ | ||
public function testAddValidUser() | ||
{ | ||
$user = [ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => 'Password1@', | ||
]; | ||
$response = $this->post('/users', $user); | ||
|
||
$this->assertSame(201, $response->getStatusCode()); | ||
$responseContent = $response->toArray(); | ||
$this->assertArrayHasKey('id', $responseContent); | ||
unset($responseContent['id']); | ||
$this->assertSame($user, $responseContent); | ||
} | ||
|
||
public function testAddDuplicateUser() | ||
{ | ||
$user = [ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => 'Password1@', | ||
]; | ||
$response = $this->post('/users', $user); | ||
|
||
$this->assertSame(409, $response->getStatusCode()); | ||
$responseContent = $response->toArray(); | ||
$this->assertSame('User already exists.', $responseContent['message']); | ||
} | ||
|
||
public function testAddUserInvalidEmail() | ||
{ | ||
$user = [ | ||
'name' => 'John Doe', | ||
'email' => 'johnexample.com', | ||
'password' => 'Password1@', | ||
]; | ||
$response = $this->post('/users', $user); | ||
|
||
$this->assertSame(400, $response->getStatusCode()); | ||
$responseContent = $response->toArray(); | ||
$this->assertSame('Invalid email address.', $responseContent['message']); | ||
} | ||
|
||
public function testAddUserInvalidPassword() | ||
{ | ||
$user = [ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => 'password', | ||
]; | ||
$response = $this->post('/users', $user); | ||
|
||
$this->assertSame(400, $response->getStatusCode()); | ||
$responseContent = $response->toArray(); | ||
$this->assertSame('Password must contain at least one uppercase letter, one lowercase letter, one number and one special character.', $responseContent['message']); | ||
} | ||
|
||
public function testAddUserInvalidName() | ||
{ | ||
$user = [ | ||
'name' => 'J1', | ||
'email' => '[email protected]', | ||
'password' => 'Password1@', | ||
]; | ||
$response = $this->post('/users', $user); | ||
|
||
$this->assertSame(400, $response->getStatusCode()); | ||
$responseContent = $response->toArray(); | ||
$this->assertSame('Name must have at least two characters and cannot contain numbers.', $responseContent['message']); | ||
} | ||
} |