From d6c76735e2611991714be66ee391697177b69d13 Mon Sep 17 00:00:00 2001 From: Beau Hastings Date: Sat, 18 Nov 2017 22:03:58 -0600 Subject: [PATCH] Fix connection resolver and static side effect Fixes #22133 Signed-off-by: Beau Hastings --- .../Database/DatabaseEloquentGlobalScopesTest.php | 14 ++++++++++++++ tests/Database/DatabaseEloquentIntegrationTest.php | 1 + tests/Database/DatabaseEloquentModelTest.php | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/tests/Database/DatabaseEloquentGlobalScopesTest.php b/tests/Database/DatabaseEloquentGlobalScopesTest.php index fe8a969729b2..719ef8e944c3 100644 --- a/tests/Database/DatabaseEloquentGlobalScopesTest.php +++ b/tests/Database/DatabaseEloquentGlobalScopesTest.php @@ -4,12 +4,26 @@ use Mockery as m; use PHPUnit\Framework\TestCase; +use Illuminate\Database\Capsule\Manager as DB; +use Illuminate\Database\Eloquent\Model as Eloquent; class DatabaseEloquentGlobalScopesTest extends TestCase { + public function setUp() + { + parent::setUp(); + + tap(new DB)->addConnection([ + 'driver' => 'sqlite', + 'database' => ':memory:', + ])->bootEloquent(); + } + public function tearDown() { m::close(); + + Eloquent::unsetConnectionResolver(); } public function testGlobalScopeIsApplied() diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 02d8b51e9163..132e532e7e83 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -125,6 +125,7 @@ public function tearDown() } Relation::morphMap([], false); + Eloquent::unsetConnectionResolver(); } /** diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index a427a8d4d0d2..7a05219b9869 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -202,6 +202,7 @@ public function testWithMethodCallsQueryBuilderCorrectly() public function testWithoutMethodRemovesEagerLoadedRelationshipCorrectly() { $model = new EloquentModelWithoutRelationStub; + $this->addMockConnection($model); $instance = $model->newInstance()->newQuery()->without('foo'); $this->assertEmpty($instance->getEagerLoads()); } @@ -1832,6 +1833,15 @@ public function setIncrementing($value) { $this->incrementing = $value; } + + public function getConnection() + { + $mock = m::mock('Illuminate\Database\Connection'); + $mock->shouldReceive('getQueryGrammar')->andReturn(m::mock('Illuminate\Database\Query\Grammars\Grammar')); + $mock->shouldReceive('getPostProcessor')->andReturn(m::mock('Illuminate\Database\Query\Processors\Processor')); + $mock->shouldReceive('getName')->andReturn('name'); + return $mock; + } } class EloquentKeyTypeModelStub extends EloquentModelStub