Skip to content

Commit eb94883

Browse files
fragkptaylorotwell
andauthored
[10.x] Add routeRoute method to test request (#49366)
* feat: add routeRoute method to test request * Update MakesHttpRequests.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 996375d commit eb94883

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php

+13-1
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
*

Diff for: tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php

+12
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)