Skip to content

Commit 832a3da

Browse files
author
Bill Harding
committed
testWithoutGlobalScopes
1 parent c6e8785 commit 832a3da

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/CacheKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
$model,
2525
$query,
2626
$macroKey,
27-
$withoutScopes,
27+
array $withoutScopes,
2828
$withoutAllScopes
2929
) {
3030
$this->eagerLoad = $eagerLoad;

src/Traits/Caching.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait Caching
1616
protected $isCachable = true;
1717
protected $scopesAreApplied = false;
1818
protected $macroKey = "";
19-
protected $withoutScopes = null;
19+
protected $withoutScopes = [];
2020
protected $withoutAllScopes = false;
2121

2222
public function __call($method, $parameters)

tests/Integration/CachedBuilder/ScopeTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,32 @@ public function testGlobalScopesWhenSwitchingContextUsingGetMethod()
156156
$this->assertEquals("B", $authorsB->first());
157157
}
158158

159+
public function testWithoutGlobalScopes()
160+
{
161+
factory(Author::class, 200)->create();
162+
$user = factory(User::class)->create(["name" => "Andrew Junior"]);
163+
$this->actingAs($user);
164+
$authorsA = (new AuthorBeginsWithScoped)
165+
->withoutGlobalScopes()
166+
->get()
167+
->map(function ($author) {
168+
return (new Str)->substr($author->name, 0, 1);
169+
})
170+
->unique();
171+
$user = factory(User::class)->create(["name" => "Barry Barry Barry"]);
172+
$this->actingAs($user);
173+
$authorsB = (new AuthorBeginsWithScoped)
174+
->withoutGlobalScopes()
175+
->get()
176+
->map(function ($author) {
177+
return (new Str)->substr($author->name, 0, 1);
178+
})
179+
->unique();
180+
181+
$this->assertGreaterThan(1, count($authorsA));
182+
$this->assertGreaterThan(1, count($authorsB));
183+
}
184+
159185
public function testLocalScopesInRelationship()
160186
{
161187
$first = "A";

0 commit comments

Comments
 (0)