Skip to content

Commit 96c9570

Browse files
committed
Added test for scopes being applied to pagination requests
1 parent b4abe94 commit 96c9570

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/Models/ModelScopeTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public function test_scopes_are_applied_to_query()
4747
'value' => 'bar',
4848
], $query->filters['and'][0]);
4949
}
50+
51+
public function test_scopes_are_applied_to_pagination_request()
52+
{
53+
Container::addConnection(new Connection());
54+
55+
$query = (new ModelScopeTestStub())->newQuery();
56+
$this->assertEmpty($query->paginate());
57+
58+
$this->assertEquals([
59+
'field' => 'foo',
60+
'operator' => '=',
61+
'value' => 'bar',
62+
], $query->filters['and'][0]);
63+
}
5064
}
5165

5266
class ModelScopeTestStub extends Model
@@ -59,6 +73,11 @@ protected static function boot()
5973
});
6074
static::addGlobalScope(new ScopeTestStub());
6175
}
76+
77+
public function newQueryBuilder(Connection $connection)
78+
{
79+
return new ModelBuilderTestStub($connection);
80+
}
6281
}
6382

6483
class ScopeTestStub implements Scope
@@ -68,3 +87,11 @@ public function apply(Builder $query, Model $model)
6887
$query->whereRaw('foo', '=', 'bar');
6988
}
7089
}
90+
91+
class ModelBuilderTestStub extends Builder
92+
{
93+
protected function runPaginate($filter, $perPage, $isCritical)
94+
{
95+
return [];
96+
}
97+
}

0 commit comments

Comments
 (0)