Skip to content

Commit 41c572e

Browse files
committed
Merge branch '10.x'
Signed-off-by: Mior Muhammad Zaki <[email protected]>
2 parents 889afc0 + eb94883 commit 41c572e

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ public static function skipWhen(Closure $callback)
5353
{
5454
static::$skipCallbacks[] = $callback;
5555
}
56+
57+
/**
58+
* Flush the middleware's global state.
59+
*
60+
* @return void
61+
*/
62+
public static function flushState()
63+
{
64+
static::$skipCallbacks = [];
65+
}
5666
}

src/Illuminate/Foundation/Http/Middleware/TrimStrings.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,14 @@ public static function skipWhen(Closure $callback)
9191
{
9292
static::$skipCallbacks[] = $callback;
9393
}
94+
95+
/**
96+
* Flush the middleware's global state.
97+
*
98+
* @return void
99+
*/
100+
public static function flushState()
101+
{
102+
static::$skipCallbacks = [];
103+
}
94104
}

src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function disableCookieEncryption()
297297
}
298298

299299
/**
300-
* Set the referer header and previous URL session value in order to simulate a previous request.
300+
* Set the referer header and previous URL session value from a given URL in order to simulate a previous request.
301301
*
302302
* @param string $url
303303
* @return $this
@@ -309,6 +309,18 @@ public function from(string $url)
309309
return $this->withHeader('referer', $url);
310310
}
311311

312+
/**
313+
* Set the referer header and previous URL session value from a given route in order to simulate a previous request.
314+
*
315+
* @param string $name
316+
* @param mixed $parameters
317+
* @return $this
318+
*/
319+
public function fromRoute(string $name, $parameters = [])
320+
{
321+
return $this->from($this->app['url']->route($name, $parameters));
322+
}
323+
312324
/**
313325
* Set the Precognition header to "true".
314326
*

src/Illuminate/Foundation/Testing/TestCase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Illuminate\Console\Application as Artisan;
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Foundation\Bootstrap\HandleExceptions;
9+
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
10+
use Illuminate\Foundation\Http\Middleware\TrimStrings;
911
use Illuminate\Queue\Queue;
1012
use Illuminate\Support\Carbon;
1113
use Illuminate\Support\Facades\Facade;
@@ -234,9 +236,11 @@ protected function tearDown(): void
234236
Component::flushCache();
235237
Component::forgetComponentsResolver();
236238
Component::forgetFactory();
237-
Queue::createPayloadUsing(null);
239+
ConvertEmptyStringsToNull::flushState();
238240
HandleExceptions::forgetApp();
241+
Queue::createPayloadUsing(null);
239242
Sleep::fake(false);
243+
TrimStrings::flushState();
240244

241245
if ($this->callbackException) {
242246
throw $this->callbackException;

tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ public function testFromSetsHeaderAndSession()
1818
$this->assertSame('previous/url', $this->app['session']->previousUrl());
1919
}
2020

21+
public function testFromRouteSetsHeaderAndSession()
22+
{
23+
$router = $this->app->make(Registrar::class);
24+
25+
$router->get('previous/url', fn () => 'ok')->name('previous-url');
26+
27+
$this->fromRoute('previous-url');
28+
29+
$this->assertSame('http://localhost/previous/url', $this->defaultHeaders['referer']);
30+
$this->assertSame('http://localhost/previous/url', $this->app['session']->previousUrl());
31+
}
32+
2133
public function testWithTokenSetsAuthorizationHeader()
2234
{
2335
$this->withToken('foobar');

0 commit comments

Comments
 (0)