Skip to content

Commit

Permalink
Adds HTTP dumps example
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Jun 14, 2024
1 parent 1706fb5 commit d1f03d7
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/CallAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Modules\Smtp\Common as SmtpActions;
use App\Modules\VarDump\Common as VarDumpActions;
use App\Modules\Inspector\Common as InspectorActions;
use App\Modules\HttpDump\Common as HttDumpActions;
use App\RandomPhraseGenerator;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Request;
Expand All @@ -27,6 +28,7 @@ class CallAction extends Controller
InspectorActions,
InspectorActions,
ProfilerActions,
HttDumpActions,
WithFaker;

private array $setUpMap = [
Expand All @@ -36,6 +38,7 @@ class CallAction extends Controller
'monolog:' => 'setUpSocketMonolog',
'var_dump:' => 'setUpVarDumper',
'inspector:' => 'setUpInspector',
'http:' => 'setUpHttp',
];

private array $replaceMap = [
Expand Down
72 changes: 72 additions & 0 deletions app/Modules/HttpDump/Common.php
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'),
]);
}
}
3 changes: 3 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@
'endpoint' => env('PROFILER_ENDPOINT', 'http://127.0.0.1/api/profiler/store'),
],

'http_dump' => [
'endpoint' => env('HTTP_DUMP_ENDPOINT', 'http://http-dump@buggregator-demo:8000'),
],
];
21 changes: 17 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
],
],
'docs' => 'https://docs.buggregator.dev/config/sentry.html',
'vendor' => 'https://docs.sentry.io/platforms/php/'
'vendor' => 'https://docs.sentry.io/platforms/php/',
],
'monolog' => [
'title' => 'Buggregator can receive logs from monolog/monolog package.',
Expand All @@ -112,7 +112,7 @@
],
],
'docs' => 'https://docs.buggregator.dev/config/monolog.html',
'vendor' => 'https://seldaek.github.io/monolog/'
'vendor' => 'https://seldaek.github.io/monolog/',
],
'smtp' => [
'title' => 'SMTP Email Testing',
Expand All @@ -139,7 +139,7 @@
],
],
'docs' => 'https://docs.buggregator.dev/config/var-dumper.html',
'vendor' => 'https://symfony.com/doc/current/components/var_dumper.html'
'vendor' => 'https://symfony.com/doc/current/components/var_dumper.html',
],
'inspector' => [
'title' => 'It can be used to receive Inspector reports from your application.',
Expand All @@ -151,7 +151,20 @@
],
],
'docs' => 'https://docs.buggregator.dev/config/inspector.html',
'vendor' => 'https://inspector.dev/'
'vendor' => 'https://inspector.dev/',
],
'http' => [
'title' => 'Http dumps',
'description' => '-',
'events' => [
'common' => [
'get',
'post',
'put',
'patch',
'delete',
],
],
],
];

Expand Down

0 comments on commit d1f03d7

Please sign in to comment.