From 8c37b0d0c0821225b4c89a7e3b4c4aeb1f560471 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Fri, 18 May 2018 00:09:13 +0200 Subject: [PATCH] Fix $withCount binding problems --- src/Illuminate/Database/Eloquent/Builder.php | 2 +- src/Illuminate/Database/Eloquent/Model.php | 20 +++-- .../Database/Eloquent/SoftDeletes.php | 4 +- .../Database/DatabaseEloquentBuilderTest.php | 2 +- tests/Database/DatabaseEloquentModelTest.php | 84 +++++++++---------- .../DatabaseSoftDeletingTraitTest.php | 2 +- 6 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index fcdb9cab551e..4a8bdb57bea9 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -219,7 +219,7 @@ public function whereKeyNot($id) public function where($column, $operator = null, $value = null, $boolean = 'and') { if ($column instanceof Closure) { - $query = $this->model->newQueryWithoutScopes(); + $query = $this->model->newUneagerQueryWithoutScopes(); $column($query); diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 8190f1178be0..1913649762e6 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -530,7 +530,7 @@ public function push() */ public function save(array $options = []) { - $query = $this->newQueryWithoutScopes(); + $query = $this->newUneagerQueryWithoutScopes(); // If the "saving" event returns false we'll bail out of the save and return // false, indicating that the save failed. This provides a chance for any @@ -815,7 +815,7 @@ public function forceDelete() */ protected function performDeleteOnModel() { - $this->setKeysForSaveQuery($this->newQueryWithoutScopes())->delete(); + $this->setKeysForSaveQuery($this->newUneagerQueryWithoutScopes())->delete(); $this->exists = false; } @@ -873,15 +873,25 @@ public function registerGlobalScopes($builder) * @return \Illuminate\Database\Eloquent\Builder|static */ public function newQueryWithoutScopes() + { + return $this->newUneagerQueryWithoutScopes() + ->with($this->with) + ->withCount($this->withCount); + } + + /** + * Get a new query builder that doesn't have any global scopes or eager loading. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newUneagerQueryWithoutScopes() { $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder()); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model // while it is constructing and executing various queries against it. - return $builder->setModel($this) - ->with($this->with) - ->withCount($this->withCount); + return $builder->setModel($this); } /** diff --git a/src/Illuminate/Database/Eloquent/SoftDeletes.php b/src/Illuminate/Database/Eloquent/SoftDeletes.php index 32b60fdcc1af..31caee9b7bc4 100644 --- a/src/Illuminate/Database/Eloquent/SoftDeletes.php +++ b/src/Illuminate/Database/Eloquent/SoftDeletes.php @@ -49,7 +49,7 @@ protected function performDeleteOnModel() if ($this->forceDeleting) { $this->exists = false; - return $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey())->forceDelete(); + return $this->newUneagerQueryWithoutScopes()->where($this->getKeyName(), $this->getKey())->forceDelete(); } return $this->runSoftDelete(); @@ -62,7 +62,7 @@ protected function performDeleteOnModel() */ protected function runSoftDelete() { - $query = $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey()); + $query = $this->newUneagerQueryWithoutScopes()->where($this->getKeyName(), $this->getKey()); $time = $this->freshTimestamp(); diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 9011fadbd4f6..489dd3fbf2f7 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -575,7 +575,7 @@ public function testNestedWhere() $nestedRawQuery = $this->getMockQueryBuilder(); $nestedQuery->shouldReceive('getQuery')->once()->andReturn($nestedRawQuery); $model = $this->getMockModel()->makePartial(); - $model->shouldReceive('newQueryWithoutScopes')->once()->andReturn($nestedQuery); + $model->shouldReceive('newUneagerQueryWithoutScopes')->once()->andReturn($nestedQuery); $builder = $this->getBuilder(); $builder->getQuery()->shouldReceive('from'); $builder->setModel($model); diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index b16d74df08f2..dc6937e5bea5 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -227,11 +227,11 @@ public function testWithMethodCallsQueryBuilderCorrectlyWithArray() public function testUpdateProcess() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('where')->once()->with('id', '=', 1); $query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true); @@ -250,11 +250,11 @@ public function testUpdateProcess() public function testUpdateProcessDoesntOverrideTimestamps() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('where')->once()->with('id', '=', 1); $query->shouldReceive('update')->once()->with(['created_at' => 'foo', 'updated_at' => 'bar'])->andReturn(1); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until'); $events->shouldReceive('fire'); @@ -269,9 +269,9 @@ public function testUpdateProcessDoesntOverrideTimestamps() public function testSaveIsCancelledIfSavingEventReturnsFalse() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(false); $model->exists = true; @@ -281,9 +281,9 @@ public function testSaveIsCancelledIfSavingEventReturnsFalse() public function testUpdateIsCancelledIfUpdatingEventReturnsFalse() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(false); @@ -295,9 +295,9 @@ public function testUpdateIsCancelledIfUpdatingEventReturnsFalse() public function testEventsCanBeFiredWithCustomEventObjects() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newQueryWithoutScopes'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newUneagerQueryWithoutScopes'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with(m::type(EloquentModelSavingEventStub::class))->andReturn(false); $model->exists = true; @@ -307,12 +307,12 @@ public function testEventsCanBeFiredWithCustomEventObjects() public function testUpdateProcessWithoutTimestamps() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'fireModelEvent'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelEventObjectStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'fireModelEvent'])->getMock(); $model->timestamps = false; $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('where')->once()->with('id', '=', 1); $query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->never())->method('updateTimestamps'); $model->expects($this->any())->method('fireModelEvent')->will($this->returnValue(true)); @@ -325,11 +325,11 @@ public function testUpdateProcessWithoutTimestamps() public function testUpdateUsesOldPrimaryKey() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('where')->once()->with('id', '=', 1); $query->shouldReceive('update')->once()->with(['id' => 2, 'foo' => 'bar'])->andReturn(1); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true); @@ -456,11 +456,11 @@ public function testFromDateTime() public function testInsertProcess() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); @@ -475,11 +475,11 @@ public function testInsertProcess() $this->assertEquals(1, $model->id); $this->assertTrue($model->exists); - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insert')->once()->with(['name' => 'taylor']); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->setIncrementing(false); @@ -498,10 +498,10 @@ public function testInsertProcess() public function testInsertIsCancelledIfCreatingEventReturnsFalse() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(false); @@ -512,11 +512,11 @@ public function testInsertIsCancelledIfCreatingEventReturnsFalse() public function testDeleteProperlyDeletesModel() { - $model = $this->getMockBuilder('Illuminate\Database\Eloquent\Model')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'touchOwners'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Database\Eloquent\Model')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'touchOwners'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('where')->once()->with('id', '=', 1)->andReturn($query); $query->shouldReceive('delete')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('touchOwners'); $model->exists = true; $model->id = 1; @@ -525,11 +525,11 @@ public function testDeleteProperlyDeletesModel() public function testPushNoRelations() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->name = 'taylor'; @@ -542,11 +542,11 @@ public function testPushNoRelations() public function testPushEmptyOneRelation() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->name = 'taylor'; @@ -561,20 +561,20 @@ public function testPushEmptyOneRelation() public function testPushOneRelation() { - $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2); $query->shouldReceive('getConnection')->once(); - $related1->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $related1->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $related1->expects($this->once())->method('updateTimestamps'); $related1->name = 'related1'; $related1->exists = false; - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->name = 'taylor'; @@ -592,11 +592,11 @@ public function testPushOneRelation() public function testPushEmptyManyRelation() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->name = 'taylor'; @@ -611,29 +611,29 @@ public function testPushEmptyManyRelation() public function testPushManyRelation() { - $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2); $query->shouldReceive('getConnection')->once(); - $related1->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $related1->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $related1->expects($this->once())->method('updateTimestamps'); $related1->name = 'related1'; $related1->exists = false; - $related2 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $related2 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'related2'], 'id')->andReturn(3); $query->shouldReceive('getConnection')->once(); - $related2->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $related2->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $related2->expects($this->once())->method('updateTimestamps'); $related2->name = 'related2'; $related2->exists = false; - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->name = 'taylor'; @@ -1648,11 +1648,11 @@ public function testNonExistingAttributeWithInternalMethodNameDoesntCallMethod() public function testIntKeyTypePreserved() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn(1); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $this->assertTrue($model->save()); $this->assertEquals(1, $model->id); @@ -1660,11 +1660,11 @@ public function testIntKeyTypePreserved() public function testStringKeyTypePreserved() { - $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentKeyTypeModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentKeyTypeModelStub')->setMethods(['newUneagerQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id'); $query->shouldReceive('getConnection')->once(); - $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); + $model->expects($this->once())->method('newUneagerQueryWithoutScopes')->will($this->returnValue($query)); $this->assertTrue($model->save()); $this->assertEquals('string id', $model->id); diff --git a/tests/Database/DatabaseSoftDeletingTraitTest.php b/tests/Database/DatabaseSoftDeletingTraitTest.php index 9efae44a130b..fdfdd43ab3f0 100644 --- a/tests/Database/DatabaseSoftDeletingTraitTest.php +++ b/tests/Database/DatabaseSoftDeletingTraitTest.php @@ -17,7 +17,7 @@ public function testDeleteSetsSoftDeletedColumn() $model = m::mock('Illuminate\Tests\Database\DatabaseSoftDeletingTraitStub'); $model->shouldDeferMissing(); // $model->shouldReceive('newQuery')->andReturn($query = m::mock('stdClass')); - $model->shouldReceive('newQueryWithoutScopes')->andReturn($query = m::mock('stdClass')); + $model->shouldReceive('newUneagerQueryWithoutScopes')->andReturn($query = m::mock('stdClass')); $query->shouldReceive('where')->once()->with('id', 1)->andReturn($query); $query->shouldReceive('update')->once()->with([ 'deleted_at' => 'date-time',