Skip to content

Commit e616fae

Browse files
authored
Merge branch 'laravel:8.x' into 8.x
2 parents 64391e3 + b757fe1 commit e616fae

File tree

9 files changed

+65
-96
lines changed

9 files changed

+65
-96
lines changed

src/Illuminate/Auth/Access/Gate.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ public function denies($ability, $arguments = [])
279279
*/
280280
public function check($abilities, $arguments = [])
281281
{
282-
if (is_array($abilities) && class_exists($abilities[0])) {
283-
$abilities = [$abilities];
284-
}
285-
286282
return collect($abilities)->every(function ($ability) use ($arguments) {
287283
return $this->inspect($ability, $arguments)->allowed();
288284
});
@@ -297,13 +293,6 @@ public function check($abilities, $arguments = [])
297293
*/
298294
public function any($abilities, $arguments = [])
299295
{
300-
// Gate::any([Policy::class, ['view', 'create']], $post)...
301-
if (isset($abilities[1]) && is_array($abilities[1])) {
302-
$abilities = collect($abilities[1])->map(function ($ability) use ($abilities) {
303-
return [$abilities[0], $ability];
304-
})->all();
305-
}
306-
307296
return collect($abilities)->contains(function ($ability) use ($arguments) {
308297
return $this->check($ability, $arguments);
309298
});
@@ -567,19 +556,6 @@ protected function resolveAuthCallback($user, $ability, array $arguments)
567556
return $callback;
568557
}
569558

570-
if (is_array($ability)) {
571-
[$class, $method] = $ability;
572-
573-
if ($this->canBeCalledWithUser($user, $class, $method)) {
574-
return $this->getCallableFromClassAndMethod($class, $method);
575-
}
576-
}
577-
578-
if (class_exists($ability) &&
579-
$this->canBeCalledWithUser($user, $ability, '__invoke')) {
580-
return $this->getCallableFromClassAndMethod($ability);
581-
}
582-
583559
if (isset($this->stringCallbacks[$ability])) {
584560
[$class, $method] = Str::parseCallback($this->stringCallbacks[$ability]);
585561

@@ -805,20 +781,6 @@ protected function resolveUser()
805781
return call_user_func($this->userResolver);
806782
}
807783

808-
/**
809-
* Get a callable from a class and method.
810-
*
811-
* @param string $class
812-
* @param string $method
813-
* @return \Closure
814-
*/
815-
protected function getCallableFromClassAndMethod($class, $method = '__invoke')
816-
{
817-
return function (...$params) use ($class, $method) {
818-
return $this->container->make($class)->{$method}(...$params);
819-
};
820-
}
821-
822784
/**
823785
* Get all of the defined abilities.
824786
*

src/Illuminate/Database/Eloquent/Relations/Concerns/CanBeOneOfMany.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ protected function getDefaultOneOfManyJoinAlias($relation)
181181
protected function newOneOfManySubQuery($groupBy, $column = null, $aggregate = null)
182182
{
183183
$subQuery = $this->query->getModel()
184-
->newQuery();
184+
->newQuery()
185+
->withoutGlobalScopes($this->removedScopes());
185186

186187
foreach (Arr::wrap($groupBy) as $group) {
187188
$subQuery->groupBy($this->qualifyRelatedColumn($group));

src/Illuminate/Foundation/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
3333
*
3434
* @var string
3535
*/
36-
const VERSION = '8.65.0';
36+
const VERSION = '8.66.0';
3737

3838
/**
3939
* The base path for the Laravel installation.

src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ protected function parseAbilityAndArguments($ability, $arguments)
5353
return [$ability, $arguments];
5454
}
5555

56-
if (is_array($ability)) {
57-
return [$ability, $arguments];
58-
}
59-
6056
$method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['function'];
6157

6258
return [$this->normalizeGuessedAbilityName($method), $ability];

src/Illuminate/Support/Testing/Fakes/BusFake.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ public function assertNotDispatched($command, $callback = null)
135135
);
136136
}
137137

138+
/**
139+
* Assert that no jobs were dispatched.
140+
*
141+
* @return void
142+
*/
143+
public function assertNothingDispatched()
144+
{
145+
PHPUnit::assertEmpty($this->commands, 'Jobs were dispatched unexpectedly.');
146+
}
147+
138148
/**
139149
* Assert if a job was explicitly dispatched synchronously based on a truth-test callback.
140150
*

tests/Auth/AuthAccessGateTest.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -759,46 +759,6 @@ public function testEveryAbilityCheckFailsIfNonePass()
759759
$this->assertFalse($gate->check(['edit', 'update'], new AccessGateTestDummy));
760760
}
761761

762-
public function testInspectPolicyCallback()
763-
{
764-
$gate = $this->getBasicGate();
765-
766-
$response = $gate->inspect([AccessGateTestPolicyWithAllPermissions::class, 'edit'], new AccessGateTestDummy);
767-
768-
$this->assertFalse($response->denied());
769-
$this->assertTrue($response->allowed());
770-
}
771-
772-
public function testInspectPolicyCallbackInvoke()
773-
{
774-
$gate = $this->getBasicGate();
775-
776-
$response = $gate->inspect(AccessGateTestGuestInvokableClass::class, new AccessGateTestDummy);
777-
778-
$this->assertFalse($response->denied());
779-
$this->assertTrue($response->allowed());
780-
}
781-
782-
public function testCheckUsingPolicyCallback()
783-
{
784-
$gate = $this->getBasicGate();
785-
786-
$this->assertTrue($gate->check(
787-
[AccessGateTestPolicyWithAllPermissions::class, 'edit'],
788-
new AccessGateTestDummy)
789-
);
790-
}
791-
792-
public function testAnyUsingPolicyCallback()
793-
{
794-
$gate = $this->getBasicGate();
795-
796-
$this->assertTrue($gate->any(
797-
[AccessGateTestPolicyWithAllPermissions::class, ['edit', 'update']],
798-
new AccessGateTestDummy)
799-
);
800-
}
801-
802762
/**
803763
* @dataProvider hasAbilitiesTestDataProvider
804764
*

tests/Database/DatabaseEloquentHasOneOfManyTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ public function testEagerLoadingAppliesConstraintsToInnerJoinSubQuery()
110110
$this->assertSame('select MAX("id") as "id_aggregate", "logins"."user_id" from "logins" where "logins"."user_id" = ? and "logins"."user_id" is not null and "logins"."user_id" in (1) group by "logins"."user_id"', $relation->getOneOfManySubQuery()->toSql());
111111
}
112112

113+
public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalScope()
114+
{
115+
HasOneOfManyTestLogin::addGlobalScope(function ($query) {
116+
$query->orderBy('id');
117+
});
118+
119+
$user = HasOneOfManyTestUser::create();
120+
$relation = $user->latest_login_without_global_scope();
121+
$relation->addEagerConstraints([$user]);
122+
$this->assertSame('select * from "logins" inner join (select MAX("id") as "id_aggregate", "logins"."user_id" from "logins" where "logins"."user_id" = ? and "logins"."user_id" is not null and "logins"."user_id" in (1) group by "logins"."user_id") as "latestOfMany" on "latestOfMany"."id_aggregate" = "logins"."id" and "latestOfMany"."user_id" = "logins"."user_id" where "logins"."user_id" = ? and "logins"."user_id" is not null', $relation->getQuery()->toSql());
123+
}
124+
125+
public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalScopeWithComplexQuery()
126+
{
127+
HasOneOfManyTestPrice::addGlobalScope(function ($query) {
128+
$query->orderBy('id');
129+
});
130+
131+
$user = HasOneOfManyTestUser::create();
132+
$relation = $user->price_without_global_scope();
133+
$this->assertSame('select * from "prices" inner join (select max("id") as "id_aggregate", "prices"."user_id" from "prices" inner join (select max("published_at") as "published_at_aggregate", "prices"."user_id" from "prices" where "published_at" < ? and "prices"."user_id" = ? and "prices"."user_id" is not null group by "prices"."user_id") as "price_without_global_scope" on "price_without_global_scope"."published_at_aggregate" = "prices"."published_at" and "price_without_global_scope"."user_id" = "prices"."user_id" where "published_at" < ? group by "prices"."user_id") as "price_without_global_scope" on "price_without_global_scope"."id_aggregate" = "prices"."id" and "price_without_global_scope"."user_id" = "prices"."user_id" where "prices"."user_id" = ? and "prices"."user_id" is not null', $relation->getQuery()->toSql());
134+
}
135+
113136
public function testQualifyingSubSelectColumn()
114137
{
115138
$user = HasOneOfManyTestUser::create();
@@ -468,6 +491,11 @@ public function latest_login_with_invalid_aggregate()
468491
return $this->hasOne(HasOneOfManyTestLogin::class, 'user_id')->ofMany('id', 'count');
469492
}
470493

494+
public function latest_login_without_global_scope()
495+
{
496+
return $this->hasOne(HasOneOfManyTestLogin::class, 'user_id')->withoutGlobalScopes()->latestOfMany();
497+
}
498+
471499
public function first_login()
472500
{
473501
return $this->hasOne(HasOneOfManyTestLogin::class, 'user_id')->ofMany('id', 'min');
@@ -522,6 +550,16 @@ public function price_with_shortcut()
522550
{
523551
return $this->hasOne(HasOneOfManyTestPrice::class, 'user_id')->latestOfMany(['published_at', 'id']);
524552
}
553+
554+
public function price_without_global_scope()
555+
{
556+
return $this->hasOne(HasOneOfManyTestPrice::class, 'user_id')->withoutGlobalScopes()->ofMany([
557+
'published_at' => 'max',
558+
'id' => 'max',
559+
], function ($q) {
560+
$q->where('published_at', '<', now());
561+
});
562+
}
525563
}
526564

527565
class HasOneOfManyTestModel extends Eloquent

tests/Foundation/FoundationAuthorizesRequestsTraitTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ protected function tearDown(): void
1717
Container::setInstance(null);
1818
}
1919

20-
public function testCallableGateCheck()
21-
{
22-
unset($_SERVER['_test.authorizes.trait']);
23-
24-
$gate = $this->getBasicGate();
25-
26-
$response = (new FoundationTestAuthorizeTraitClass)->authorize([FoundationAuthorizesRequestTestPolicy::class, 'create']);
27-
28-
$this->assertInstanceOf(Response::class, $response);
29-
$this->assertTrue($_SERVER['_test.authorizes.trait.policy']);
30-
}
31-
3220
public function testBasicGateCheck()
3321
{
3422
unset($_SERVER['_test.authorizes.trait']);

tests/Support/SupportTestingBusFakeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,20 @@ public function testAssertNotDispatchedSyncClosure()
362362
}
363363
}
364364

365+
public function testAssertNothingDispatched()
366+
{
367+
$this->fake->assertNothingDispatched();
368+
369+
$this->fake->dispatch(new BusJobStub);
370+
371+
try {
372+
$this->fake->assertNothingDispatched();
373+
$this->fail();
374+
} catch (ExpectationFailedException $e) {
375+
$this->assertThat($e, new ExceptionMessage('Jobs were dispatched unexpectedly.'));
376+
}
377+
}
378+
365379
public function testAssertDispatchedWithIgnoreClass()
366380
{
367381
$dispatcher = m::mock(QueueingDispatcher::class);

0 commit comments

Comments
 (0)