/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Integration/Auth/ForgotPasswordWithoutDefaultRoutesTest.php
125 строк
4 KB
Lucas Michot
[13.x] Simplify most of the exceptions expectations (#61049)
05 авг 2026, 18:34
Не верифицирован
05 авг 2026, 18:34
910cd94
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Integration\Auth; use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Password; use Illuminate\Support\Str; use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; use Orchestra\Testbench\Attributes\WithMigration; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; use Symfony\Component\Routing\Exception\RouteNotFoundException; #[WithMigration] class ForgotPasswordWithoutDefaultRoutesTest extends TestCase { use RefreshDatabase; protected function tearDown(): void { ResetPassword::$createUrlCallback = null; ResetPassword::$toMailCallback = null; parent::tearDown(); } protected function defineEnvironment($app) { $app['config']->set('app.key', Str::random(32)); $app['config']->set('auth.providers.users.model', AuthenticationTestUser::class); } protected function defineRoutes($router) { $router->get('custom/password/reset/{token}', function ($token) { return 'Custom reset password!'; })->name('custom.password.reset'); } public function testItCannotSendForgotPasswordEmail() { $this->expectExceptionObject(new RouteNotFoundException('Route [password.reset] not defined.')); Notification::fake(); UserFactory::new()->create(); $user = AuthenticationTestUser::first(); Password::broker()->sendResetLink([ 'email' => $user->email, ]); Notification::assertSentTo( $user, function (ResetPassword $notification, $channels) use ($user) { $message = $notification->toMail($user); return ! is_null($notification->token) && $message->actionUrl === route('custom.password.reset', ['token' => $notification->token, 'email' => $user->email]); } ); } public function testItCanSendForgotPasswordEmailViaCreateUrlUsing() { Notification::fake(); ResetPassword::createUrlUsing(function ($user, string $token) { return route('custom.password.reset', $token); }); UserFactory::new()->create(); $user = AuthenticationTestUser::first(); Password::broker()->sendResetLink([ 'email' => $user->email, ]); Notification::assertSentTo( $user, function (ResetPassword $notification, $channels) use ($user) { $message = $notification->toMail($user); return ! is_null($notification->token) && $message->actionUrl === route('custom.password.reset', ['token' => $notification->token]); } ); } public function testItCanSendForgotPasswordEmailViaToMailUsing() { Notification::fake(); ResetPassword::toMailUsing(function ($notifiable, $token) { return (new MailMessage) ->subject(__('Reset your password')) ->line(__('You are receiving this email because we received a password reset request for your account.')) ->action(__('Reset Password'), route('custom.password.reset', $token)) ->line(__('If you did not request a password reset, no further action is required.')); }); UserFactory::new()->create(); $user = AuthenticationTestUser::first(); Password::broker()->sendResetLink([ 'email' => $user->email, ]); Notification::assertSentTo( $user, function (ResetPassword $notification, $channels) use ($user) { $message = $notification->toMail($user); return ! is_null($notification->token) && $message->actionUrl === route('custom.password.reset', ['token' => $notification->token]); } ); } }