Skip to content

Commit c527625

Browse files
committed
Merge branch '9.x' into 10.x
# Conflicts: # CHANGELOG.md # composer.json # src/Illuminate/Foundation/Application.php # src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
2 parents a24b75e + 6114330 commit c527625

File tree

15 files changed

+192
-41
lines changed

15 files changed

+192
-41
lines changed

src/Illuminate/Cache/CacheManager.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function store($name = null)
5858
{
5959
$name = $name ?: $this->getDefaultDriver();
6060

61-
return $this->stores[$name] = $this->get($name);
61+
return $this->stores[$name] ??= $this->resolve($name);
6262
}
6363

6464
/**
@@ -72,17 +72,6 @@ public function driver($driver = null)
7272
return $this->store($driver);
7373
}
7474

75-
/**
76-
* Attempt to get the store from the local cache.
77-
*
78-
* @param string $name
79-
* @return \Illuminate\Contracts\Cache\Repository
80-
*/
81-
protected function get($name)
82-
{
83-
return $this->stores[$name] ?? $this->resolve($name);
84-
}
85-
8675
/**
8776
* Resolve the given store.
8877
*

src/Illuminate/Foundation/Bootstrap/HandleExceptions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ public function handleException(Throwable $e)
181181
try {
182182
$this->getExceptionHandler()->report($e);
183183
} catch (Exception) {
184-
//
184+
$exceptionHandlerFailed = true;
185185
}
186186

187187
if (static::$app->runningInConsole()) {
188188
$this->renderForConsole($e);
189+
190+
if ($exceptionHandlerFailed ?? false) {
191+
exit(1);
192+
}
189193
} else {
190194
$this->renderHttpResponse($e);
191195
}

src/Illuminate/Foundation/Testing/WithFaker.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ protected function faker($locale = null)
4343
*/
4444
protected function makeFaker($locale = null)
4545
{
46-
$locale ??= config('app.faker_locale', Factory::DEFAULT_LOCALE);
46+
if (isset($this->app)) {
47+
$locale ??= $this->app->make('config')->get('app.faker_locale', Factory::DEFAULT_LOCALE);
4748

48-
if (isset($this->app) && $this->app->bound(Generator::class)) {
49-
return $this->app->make(Generator::class, ['locale' => $locale]);
49+
if ($this->app->bound(Generator::class)) {
50+
return $this->app->make(Generator::class, ['locale' => $locale]);
51+
}
5052
}
5153

52-
return Factory::create($locale);
54+
return Factory::create($locale ?? Factory::DEFAULT_LOCALE);
5355
}
5456
}

src/Illuminate/Queue/Queue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function () use ($payload, $queue, $delay, $callback, $job) {
325325
*/
326326
protected function shouldDispatchAfterCommit($job)
327327
{
328-
if (is_object($job) && isset($job->afterCommit)) {
328+
if (! $job instanceof Closure && is_object($job) && isset($job->afterCommit)) {
329329
return $job->afterCommit;
330330
}
331331

src/Illuminate/Routing/PendingSingletonResourceRegistration.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,23 @@ public function except($methods)
9090
/**
9191
* Indicate that the resource should have creation and storage routes.
9292
*
93-
* @param bool $creatable
9493
* @return $this
9594
*/
96-
public function creatable($creatable = true)
95+
public function creatable()
9796
{
98-
$this->options['creatable'] = $creatable;
97+
$this->options['creatable'] = true;
9998

10099
return $this;
101100
}
102101

103102
/**
104103
* Indicate that the resource should have a deletion route.
105104
*
106-
* @param bool $destroyable
107105
* @return $this
108106
*/
109-
public function destroyable($destroyable = true)
107+
public function destroyable()
110108
{
111-
$this->options['destroyable'] = $destroyable;
109+
$this->options['destroyable'] = true;
112110

113111
return $this;
114112
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public function assertListening($expectedEvent, $expectedListener)
9595
if (Str::contains($expectedListener, '@')) {
9696
$normalizedListener = Str::parseCallback($expectedListener);
9797
} else {
98-
$normalizedListener = [$expectedListener, 'handle'];
98+
$normalizedListener = [
99+
$expectedListener,
100+
method_exists($expectedListener, 'handle') ? 'handle' : '__invoke',
101+
];
99102
}
100103
}
101104
}

src/Illuminate/Validation/ValidationData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected static function extractValuesForWildcards($masterData, $data, $attribu
5454
{
5555
$keys = [];
5656

57-
$pattern = str_replace('\*', '[^\.]+', preg_quote($attribute));
57+
$pattern = str_replace('\*', '[^\.]+', preg_quote($attribute, '/'));
5858

5959
foreach ($data as $key => $value) {
6060
if ((bool) preg_match('/^'.$pattern.'/', $key, $matches)) {

tests/Integration/Console/CommandSchedulingTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ protected function tearDown(): void
6565
/**
6666
* @dataProvider executionProvider
6767
*/
68-
public function testExecutionOrder($background)
68+
public function testExecutionOrder($background, $expected)
6969
{
7070
$event = $this->app->make(Schedule::class)
7171
->command("test:{$this->id}")
7272
->onOneServer()
7373
->after(function () {
74-
$this->fs->append($this->logfile, "after\n");
74+
$this->fs->append($this->logfile, "foreground:after\n");
7575
})
7676
->before(function () {
77-
$this->fs->append($this->logfile, "before\n");
77+
$this->fs->append($this->logfile, "foreground:before\n");
7878
});
7979

8080
if ($background) {
@@ -89,17 +89,17 @@ public function testExecutionOrder($background)
8989
if ($background) {
9090
// Since our command is running in a separate process, we need to wait
9191
// until it has finished executing before running our assertions.
92-
$this->waitForLogMessages('before', 'handled', 'after');
92+
$this->waitForLogMessages(...$expected);
9393
}
9494

95-
$this->assertLogged('before', 'handled', 'after');
95+
$this->assertLogged(...$expected);
9696
}
9797

9898
public static function executionProvider()
9999
{
100100
return [
101-
'Foreground' => [false],
102-
'Background' => [true],
101+
'Foreground' => [false, ['foreground:before', 'handled', 'foreground:after']],
102+
'Background' => [true, ['foreground:before', 'handled', 'background:after']],
103103
];
104104
}
105105

@@ -184,11 +184,11 @@ public function handle()
184184
\$schedule->command("test:{$this->id}")
185185
->after(function() use (\$fs) {
186186
\$logfile = {$logfile};
187-
\$fs->append(\$logfile, "after\\n");
187+
\$fs->append(\$logfile, "background:after\\n");
188188
})
189189
->before(function() use (\$fs) {
190190
\$logfile = {$logfile};
191-
\$fs->append(\$logfile, "before\\n");
191+
\$fs->append(\$logfile, "background:before\\n");
192192
});
193193
});
194194
});

tests/Integration/Events/EventFakeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public function testAssertListening()
147147
'Illuminate\\Tests\\Integration\\Events\\PostAutoEventSubscriber@handle',
148148
PostEventSubscriber::class,
149149
[PostEventSubscriber::class, 'foo'],
150+
InvokableEventSubscriber::class,
150151
]);
151152

152153
foreach ($listenersOfSameEventInRandomOrder as $listener) {
@@ -172,6 +173,7 @@ public function testAssertListening()
172173
Event::assertListening(NonImportantEvent::class, Closure::class);
173174
Event::assertListening('eloquent.saving: '.Post::class, PostObserver::class.'@saving');
174175
Event::assertListening('eloquent.saving: '.Post::class, [PostObserver::class, 'saving']);
176+
Event::assertListening('event', InvokableEventSubscriber::class);
175177
}
176178

177179
public function testMissingMethodsAreForwarded()
@@ -238,3 +240,11 @@ public function saving(Post $post)
238240
$post->slug = sprintf('%s-Test', $post->title);
239241
}
240242
}
243+
244+
class InvokableEventSubscriber
245+
{
246+
public function __invoke($event)
247+
{
248+
//
249+
}
250+
}

tests/Integration/Foundation/ExceptionHandlerTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@
66
use Illuminate\Auth\Access\Response;
77
use Illuminate\Support\Facades\Route;
88
use Orchestra\Testbench\TestCase;
9+
use Symfony\Component\Process\PhpProcess;
910

1011
class ExceptionHandlerTest extends TestCase
1112
{
13+
/**
14+
* Resolve application HTTP exception handler.
15+
*
16+
* @param \Illuminate\Foundation\Application $app
17+
* @return void
18+
*/
19+
protected function resolveApplicationExceptionHandler($app)
20+
{
21+
$app->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'Illuminate\Foundation\Exceptions\Handler');
22+
}
23+
1224
public function testItRendersAuthorizationExceptions()
1325
{
1426
Route::get('test-route', fn () => Response::deny('expected message', 321)->authorize());
@@ -107,4 +119,36 @@ public function testItHasFallbackErrorMessageForUnknownStatusCodes()
107119
'message' => 'Whoops, looks like something went wrong.',
108120
]);
109121
}
122+
123+
/**
124+
* @dataProvider exitCodesProvider
125+
*/
126+
public function testItReturnsNonZeroExitCodesForUncaughtExceptions($providers, $successful)
127+
{
128+
$basePath = static::applicationBasePath();
129+
$providers = json_encode($providers, true);
130+
131+
$process = new PhpProcess(<<<EOF
132+
<?php
133+
134+
require 'vendor/autoload.php';
135+
136+
\$laravel = Orchestra\Testbench\Foundation\Application::create(basePath: '$basePath', options: ['extra' => ['providers' => $providers]]);
137+
\$laravel->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'Illuminate\Foundation\Exceptions\Handler');
138+
139+
\$kernel = \$laravel[Illuminate\Contracts\Console\Kernel::class];
140+
141+
return \$kernel->call('throw-exception-command');
142+
EOF, __DIR__.'/../../../', ['APP_RUNNING_IN_CONSOLE' => true]);
143+
144+
$process->run();
145+
146+
$this->assertSame($successful, $process->isSuccessful());
147+
}
148+
149+
public static function exitCodesProvider()
150+
{
151+
yield 'Throw exception' => [[Fixtures\Providers\ThrowUncaughtExceptionServiceProvider::class], false];
152+
yield 'Do not throw exception' => [[Fixtures\Providers\ThrowExceptionServiceProvider::class], true];
153+
}
110154
}

0 commit comments

Comments
 (0)