-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1706fb5
commit d1f03d7
Showing
4 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Modules\HttpDump; | ||
|
||
use App\RandomPhraseGenerator; | ||
use Illuminate\Http\Client\PendingRequest; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
trait Common | ||
{ | ||
protected string $url; | ||
private PendingRequest $httpClient; | ||
|
||
public function setUpHttp(): void | ||
{ | ||
$this->url = config('services.http_dump.endpoint'); | ||
|
||
$domain = parse_url($this->url, PHP_URL_HOST); | ||
$this->httpClient = Http::withHeaders([ | ||
'X-Header' => 'Buggregator', | ||
]) | ||
->withCookies([ | ||
'some-token' => 'some-value', | ||
], $domain) | ||
->withUserAgent('Buggregator'); | ||
} | ||
|
||
/** @test */ | ||
public function httpGet(RandomPhraseGenerator $generator): void | ||
{ | ||
$this->httpClient->get(\sprintf('%s/some-path', $this->url), [ | ||
'message' => $generator->generate('Buggregator'), | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function httpPost(RandomPhraseGenerator $generator): void | ||
{ | ||
$this->httpClient | ||
->attach([ | ||
['file', fopen(app()->resourcePath('images/logo.svg'), 'r')], | ||
['message', $generator->generate('Buggregator'),], | ||
]) | ||
->post(\sprintf('%s/some-path', $this->url)); | ||
} | ||
|
||
/** @test */ | ||
public function httpPut(RandomPhraseGenerator $generator): void | ||
{ | ||
$this->httpClient->put(\sprintf('%s/some-path', $this->url), [ | ||
'message' => $generator->generate('Buggregator'), | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function httpPath(RandomPhraseGenerator $generator): void | ||
{ | ||
$this->httpClient->patch(\sprintf('%s/some-path', $this->url), [ | ||
'message' => $generator->generate('Buggregator'), | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function httpDelete(RandomPhraseGenerator $generator): void | ||
{ | ||
$this->httpClient->delete(\sprintf('%s/some-path', $this->url), [ | ||
'message' => $generator->generate('Buggregator'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters