2017-12-23 02:46:46 +08:00
|
|
|
<?php
|
|
|
|
|
2020-02-24 06:21:26 +08:00
|
|
|
use App\Events\UserRegistered;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\Enums\UserState;
|
2020-02-24 06:21:26 +08:00
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
2017-12-23 02:46:46 +08:00
|
|
|
|
|
|
|
class RegistrationTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A basic test example.
|
|
|
|
*
|
2018-08-27 02:50:08 +08:00
|
|
|
* @throws Exception
|
2018-08-27 02:51:47 +08:00
|
|
|
*
|
|
|
|
* @return void
|
2017-12-23 02:46:46 +08:00
|
|
|
*/
|
|
|
|
public function testRegistration()
|
|
|
|
{
|
|
|
|
Event::fake();
|
2020-02-24 06:21:26 +08:00
|
|
|
Notification::fake();
|
2017-12-23 02:46:46 +08:00
|
|
|
|
|
|
|
$userSvc = app('App\Services\UserService');
|
|
|
|
|
2018-03-01 05:27:46 +08:00
|
|
|
setting('pilots.auto_accept', true);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2020-02-24 06:21:26 +08:00
|
|
|
$attrs = factory(App\Models\User::class)->make()->toArray();
|
|
|
|
$attrs['password'] = Hash::make('secret');
|
|
|
|
$user = $userSvc->createUser($attrs);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2017-12-31 10:40:32 +08:00
|
|
|
$this->assertEquals(UserState::ACTIVE, $user->state);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2020-02-24 06:21:26 +08:00
|
|
|
Event::assertDispatched(UserRegistered::class, function ($e) use ($user) {
|
2017-12-23 02:46:46 +08:00
|
|
|
return $e->user->id === $user->id
|
|
|
|
&& $e->user->state === $user->state;
|
|
|
|
});
|
|
|
|
|
2020-02-24 06:21:26 +08:00
|
|
|
/*Notification::assertSentTo(
|
|
|
|
[$user],
|
|
|
|
\App\Notifications\Messages\UserRegistered::class
|
|
|
|
);*/
|
2017-12-23 02:46:46 +08:00
|
|
|
}
|
|
|
|
}
|