/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php
58 строк
2 KB
Mior Muhammad Zaki
[10.x] Test Improvements for Auth tests (#50683)
21 мар 2024, 11:46
Не верифицирован
21 мар 2024, 11:46
1ad9354
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Integration\Auth; use Illuminate\Database\QueryException; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; use Orchestra\Testbench\TestCase; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('pdo_mysql')] class ApiAuthenticationWithEloquentTest extends TestCase { protected function defineEnvironment($app) { // Auth configuration $app['config']->set('auth.defaults.guard', 'api'); $app['config']->set('auth.guards.api', [ 'driver' => 'token', 'provider' => 'users', 'hash' => false, ]); // Database configuration $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'username' => 'root', 'password' => 'invalid-credentials', 'database' => 'forge', 'prefix' => '', ]); } public function testAuthenticationViaApiWithEloquentUsingWrongDatabaseCredentialsShouldNotCauseInfiniteLoop() { Route::get('/auth', function () { return 'success'; })->middleware('auth:api'); $this->expectException(QueryException::class); $this->expectExceptionMessage("Access denied for user 'root'@"); try { $this->withoutExceptionHandling()->get('/auth', ['Authorization' => 'Bearer whatever']); } catch (QueryException $e) { if (Str::startsWith($e->getMessage(), 'SQLSTATE[HY000] [2002]')) { $this->markTestSkipped('MySQL instance required.'); } throw $e; } } }