Skip to content

Commit

Permalink
Fix connection resolver and static side effect
Browse files Browse the repository at this point in the history
Fixes laravel#22133

Signed-off-by: Beau Hastings <beausy@gmail.com>
  • Loading branch information
Beau Hastings committed Nov 22, 2017
1 parent c3a01f2 commit d6c7673
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/Database/DatabaseEloquentGlobalScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function tearDown()
}

Relation::morphMap([], false);
Eloquent::unsetConnectionResolver();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6c7673

Please sign in to comment.