Skip to content

Commit

Permalink
[5.6] Let Exception Handler do the reporting (#24864)
Browse files Browse the repository at this point in the history
* Let Exception Handler do the reporting

Co-authored-by: Abdala Cerqueira <abdala.cerqueira@gmail.com>

* StyleCI

* Fix error message

Co-authored-by: Abdala Cerqueira <abdala.cerqueira@gmail.com>
  • Loading branch information
2 people authored and taylorotwell committed Jul 16, 2018
1 parent 89fc860 commit 23f6279
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/Illuminate/Database/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Illuminate\Database\PostgresConnection;
use Illuminate\Database\SqlServerConnection;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;

class ConnectionFactory
{
Expand Down Expand Up @@ -182,9 +181,7 @@ protected function createPdoResolverWithHosts(array $config)
try {
return $this->createConnector($config)->connect($config);
} catch (PDOException $e) {
if (count($hosts) - 1 === $key && $this->container->bound(ExceptionHandler::class)) {
$this->container->make(ExceptionHandler::class)->report($e);
}
continue;
}
}

Expand Down
51 changes: 51 additions & 0 deletions tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Illuminate\Tests\Integration\Auth\ApiAuthenticationWithEloquentTest;

use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Route;
use Illuminate\Database\QueryException;

class ApiAuthenticationWithEloquentTest extends TestCase
{
protected function getEnvironmentSetUp($app)
{
$app['config']->set('app.debug', 'true');

// Auth configuration
$app['config']->set('auth.defaults.guard', 'api');
$app['config']->set('auth.providers.users.model', User::class);

// 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' => '',
]);
}

/**
* @test
*/
public function authentication_via_api_with_eloquent_using_wrong_database_credentials_should_not_cause_infinite_loop()
{
Route::get('/auth', function () {
return 'success';
})->middleware('auth:api');

$this->expectException(QueryException::class);

$this->expectExceptionMessage("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from `users` where `api_token` = whatever limit 1)");

$this->withoutExceptionHandling()->get('/auth', ['Authorization' => 'Bearer whatever']);
}
}

class User extends \Illuminate\Foundation\Auth\User
{
}
2 changes: 0 additions & 2 deletions tests/Integration/Database/EloquentRelationshipsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class EloquentRelationshipsTest extends TestCase
{
/**
* @test
* @group f
*/
public function standard_relationships()
{
Expand All @@ -41,7 +40,6 @@ public function standard_relationships()

/**
* @test
* @group f
*/
public function overridden_relationships()
{
Expand Down

0 comments on commit 23f6279

Please sign in to comment.