Skip to content

Commit

Permalink
Merge branch '10.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 14, 2023
2 parents 889afc0 + eb94883 commit 41c572e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public static function skipWhen(Closure $callback)
{
static::$skipCallbacks[] = $callback;
}

/**
* Flush the middleware's global state.
*
* @return void
*/
public static function flushState()
{
static::$skipCallbacks = [];
}
}
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Http/Middleware/TrimStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ public static function skipWhen(Closure $callback)
{
static::$skipCallbacks[] = $callback;
}

/**
* Flush the middleware's global state.
*
* @return void
*/
public static function flushState()
{
static::$skipCallbacks = [];
}
}
14 changes: 13 additions & 1 deletion src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function disableCookieEncryption()
}

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

/**
* Set the referer header and previous URL session value from a given route in order to simulate a previous request.
*
* @param string $name
* @param mixed $parameters
* @return $this
*/
public function fromRoute(string $name, $parameters = [])
{
return $this->from($this->app['url']->route($name, $parameters));
}

/**
* Set the Precognition header to "true".
*
Expand Down
6 changes: 5 additions & 1 deletion src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Console\Application as Artisan;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Bootstrap\HandleExceptions;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
use Illuminate\Queue\Queue;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Facade;
Expand Down Expand Up @@ -234,9 +236,11 @@ protected function tearDown(): void
Component::flushCache();
Component::forgetComponentsResolver();
Component::forgetFactory();
Queue::createPayloadUsing(null);
ConvertEmptyStringsToNull::flushState();
HandleExceptions::forgetApp();
Queue::createPayloadUsing(null);
Sleep::fake(false);
TrimStrings::flushState();

if ($this->callbackException) {
throw $this->callbackException;
Expand Down
12 changes: 12 additions & 0 deletions tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public function testFromSetsHeaderAndSession()
$this->assertSame('previous/url', $this->app['session']->previousUrl());
}

public function testFromRouteSetsHeaderAndSession()
{
$router = $this->app->make(Registrar::class);

$router->get('previous/url', fn () => 'ok')->name('previous-url');

$this->fromRoute('previous-url');

$this->assertSame('http://localhost/previous/url', $this->defaultHeaders['referer']);
$this->assertSame('http://localhost/previous/url', $this->app['session']->previousUrl());
}

public function testWithTokenSetsAuthorizationHeader()
{
$this->withToken('foobar');
Expand Down

0 comments on commit 41c572e

Please sign in to comment.