Skip to content

Commit 99edb26

Browse files
committed
Merge branch 'testing-authorization-helper' into 7.x
2 parents e978475 + 79383a1 commit 99edb26

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public function withHeader(string $name, string $value)
8080
return $this;
8181
}
8282

83+
/**
84+
* Add an authorization token for the request.
85+
*
86+
* @param string $token
87+
* @param string $type
88+
* @return $this
89+
*/
90+
public function withToken(string $token, string $type = 'Bearer')
91+
{
92+
return $this->withHeader('Authorization', $type.' '.$token);
93+
}
94+
8395
/**
8496
* Flush all the configured headers.
8597
*

tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ public function testFromSetsHeaderAndSession()
1414
$this->assertSame('previous/url', $this->app['session']->previousUrl());
1515
}
1616

17+
public function testWithTokenSetsAuthorizationHeader()
18+
{
19+
$this->withToken('foobar');
20+
$this->assertSame('Bearer foobar', $this->defaultHeaders['Authorization']);
21+
22+
$this->withToken('foobar', 'Basic');
23+
$this->assertSame('Basic foobar', $this->defaultHeaders['Authorization']);
24+
}
25+
1726
public function testWithoutAndWithMiddleware()
1827
{
1928
$this->assertFalse($this->app->has('middleware.disable'));

0 commit comments

Comments
 (0)