-
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
Showing
3 changed files
with
129 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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact group@hyperf.io | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace HyperfTest\Cases\Auth; | ||
|
||
|
||
use App\Model\User; | ||
use Faker; | ||
use Hyperf\Testing\TestCase; | ||
|
||
class SignInTest extends TestCase | ||
{ | ||
protected const ROUTE = '/auth/sign-in'; | ||
|
||
protected Faker\Generator $faker; | ||
protected User $user; | ||
protected string $password; | ||
|
||
public function __construct($name = null) | ||
{ | ||
parent::__construct($name); | ||
$this->faker = Faker\Factory::create(); | ||
} | ||
|
||
public function setUp(): void | ||
{ | ||
$this->password = $this->faker->password(); | ||
|
||
$this->user = factory(User::class)->create([ | ||
'password' => password_hash($this->password, PASSWORD_DEFAULT), | ||
]); | ||
} | ||
|
||
public function testSignIn() | ||
{ | ||
$data = [ | ||
'email' => $this->user->email, | ||
'password' => $this->password, | ||
]; | ||
|
||
$response = $this->post(self::ROUTE, $data); | ||
$response->assertOk()->assertJsonStructure(['token']); | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact group@hyperf.io | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace HyperfTest\Cases\Auth; | ||
|
||
|
||
use App\Enum\UserTypeEnum; | ||
use Faker; | ||
use Hyperf\Testing\TestCase; | ||
|
||
class SignUpTest extends TestCase | ||
{ | ||
protected const ROUTE = '/auth/sign-up'; | ||
|
||
protected Faker\Generator $faker; | ||
|
||
public function __construct($name = null) | ||
{ | ||
parent::__construct($name); | ||
$this->faker = Faker\Factory::create(); | ||
} | ||
|
||
public function testSignUp() | ||
{ | ||
$data = [ | ||
'type' => UserTypeEnum::COMMON->value, | ||
'firstName' => $this->faker->firstName, | ||
'lastName' => $this->faker->lastName, | ||
'document' => $this->faker->numerify('###########'), | ||
'email' => $this->faker->email, | ||
'password' => $password = $this->faker->password, | ||
'passwordConfirmation' => $password, | ||
]; | ||
|
||
$response = $this->post(self::ROUTE, $data); | ||
$response->assertCreated()->assertJsonStructure([ | ||
'data' => [ | ||
'id', | ||
'type', | ||
'firstName', | ||
'lastName', | ||
'document', | ||
'email', | ||
] | ||
]); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Enum\UserTypeEnum; | ||
use App\Model\User; | ||
use Faker\Generator as Faker; | ||
use Hyperf\Database\Model\Factory; | ||
|
||
/* @var Factory $factory */ | ||
$factory->define(User::class, function (Faker $faker) { | ||
return [ | ||
'type' => $faker->randomElement(UserTypeEnum::values()), | ||
'first_name' => $faker->firstName, | ||
'last_name' => $faker->lastName, | ||
'email' => $faker->unique()->safeEmail, | ||
'password' => password_hash('password', PASSWORD_DEFAULT), | ||
'document' => $faker->numerify('###########'), | ||
]; | ||
}); |