Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix Http global middleware for queue, octane, and dependecy injection #47915

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Foundation\MaintenanceModeManager;
use Illuminate\Foundation\Precognition;
use Illuminate\Foundation\Vite;
use Illuminate\Http\Client\Factory as HttpFactory;
use Illuminate\Http\Request;
use Illuminate\Log\Events\MessageLogged;
use Illuminate\Support\AggregateServiceProvider;
Expand Down Expand Up @@ -41,6 +42,7 @@ class FoundationServiceProvider extends AggregateServiceProvider
* @var array
*/
public $singletons = [
HttpFactory::class => HttpFactory::class,
Vite::class => Vite::class,
];

Expand Down
24 changes: 24 additions & 0 deletions tests/Integration/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Illuminate\Tests\Integration\Http;

use Illuminate\Http\Client\Factory;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Http;
use Orchestra\Testbench\TestCase;

class HttpClientTest extends TestCase
{
public function testGlobalMiddlewarePersistsAfterFacadeFlush(): void
{
Http::macro('getGlobalMiddleware', fn () => $this->globalMiddleware);
Http::globalRequestMiddleware(fn ($request) => $request->withHeader('User-Agent', 'Example Application/1.0'));
Http::globalRequestMiddleware(fn ($request) => $request->withHeader('User-Agent', 'Example Application/1.0'));

$this->assertCount(2, Http::getGlobalMiddleware());

Facade::clearResolvedInstances();

$this->assertCount(2, Http::getGlobalMiddleware());
}
}