Skip to content

Commit fdd0185

Browse files
committed
Added web UI with test event buttons.
1 parent 0d2f1c1 commit fdd0185

23 files changed

+909
-862
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ APP_URL=http://localhost
77
LOG_CHANNEL=slack
88
LOG_LEVEL=debug
99

10-
DB_CONNECTION=mysql
10+
DB_CONNECTION=sqlite
1111
DB_HOST=127.0.0.1
1212
DB_PORT=3306
13-
DB_DATABASE=laravel
13+
DB_DATABASE=:memory:
1414
DB_USERNAME=root
1515
DB_PASSWORD=
1616

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Http\Controllers;
5+
6+
use App\Modules\Monolog\Common as MonologActions;
7+
use App\Modules\Ray\RayCommon as RayCommonActions;
8+
use App\Modules\Ray\RayLaravel as RayLaravelActions;
9+
use App\Modules\Sentry\Common as SentryActions;
10+
use App\Modules\Smtp\Common as SmtpActions;
11+
use App\Modules\VarDump\Common as VarDumpActions;
12+
use App\Modules\Inspector\Common as InspectorActions;
13+
use Illuminate\Foundation\Testing\WithFaker;
14+
use Illuminate\Http\Request;
15+
use Illuminate\Support\Str;
16+
17+
class CallAction extends Controller
18+
{
19+
use MonologActions,
20+
RayCommonActions, RayLaravelActions,
21+
SentryActions,
22+
SmtpActions,
23+
VarDumpActions,
24+
InspectorActions,
25+
WithFaker;
26+
27+
private array $setUpMap = [
28+
'ray_log:' => 'setUpRayLogger',
29+
'monolog:' => 'setUpSocketMonolog',
30+
'sentry:' => 'setupSentryLogger',
31+
'var_dump:' => 'setUpVarDumper',
32+
'inspector:' => 'setUpInspector'
33+
];
34+
35+
private array $replaceMap = [
36+
'ray_common:' => 'ray:',
37+
'ray_laravel:' => 'ray:',
38+
];
39+
40+
private array $actionsMap = [
41+
'ray_log:debug' => 'monologDebug',
42+
'ray_log:info' => 'monologInfo',
43+
'ray_log:warning' => 'monologWarning',
44+
'ray_log:error' => 'monologError',
45+
'ray_log:critical' => 'monologCritical',
46+
'ray_log:notice' => 'monologNotice',
47+
'ray_log:alert' => 'monologAlert',
48+
'ray_log:emergency' => 'monologEmergency',
49+
'ray_log:exception' => 'monologException',
50+
];
51+
52+
public function __invoke(Request $request)
53+
{
54+
$this->setUpFaker();
55+
56+
$action = $request->action;
57+
58+
foreach ($this->replaceMap as $from => $to) {
59+
$action = str_replace($from, $to, $action);
60+
}
61+
62+
foreach ($this->setUpMap as $a => $method) {
63+
if (Str::startsWith($action, $a)) {
64+
call_user_func([$this, $method]);
65+
break;
66+
}
67+
}
68+
69+
foreach ($this->actionsMap as $a => $method) {
70+
if ($action === $a) {
71+
call_user_func([$this, $method]);
72+
return 'ok';
73+
}
74+
}
75+
76+
$method = Str::studly(Str::replace(':', '_', $action));
77+
78+
if (method_exists($this, $method)) {
79+
call_user_func([$this, $method]);
80+
return 'ok';
81+
}
82+
83+
abort(404);
84+
}
85+
}

app/Http/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Kernel extends HttpKernel
3535
\Illuminate\Session\Middleware\StartSession::class,
3636
// \Illuminate\Session\Middleware\AuthenticateSession::class,
3737
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
38-
\App\Http\Middleware\VerifyCsrfToken::class,
38+
// \App\Http\Middleware\VerifyCsrfToken::class,
3939
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4040
],
4141

app/Modules/Inspector/Common.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Modules\Inspector;
5+
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Artisan;
8+
use Illuminate\Support\Facades\Route;
9+
10+
trait Common
11+
{
12+
public function setUpInspector()
13+
{
14+
ray()->disable();
15+
}
16+
17+
/** @test */
18+
public function inspectorRequest()
19+
{
20+
$request = Request::create('/inspector');
21+
Route::dispatch($request);
22+
}
23+
24+
/** @test */
25+
public function inspectorCommand()
26+
{
27+
Artisan::call('inspector:test');
28+
}
29+
}

app/Modules/Monolog/Common.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Modules\Monolog;
5+
6+
trait Common
7+
{
8+
public function setUpSocketMonolog()
9+
{
10+
logger()->setDefaultDriver('socket');
11+
ray()->disable();
12+
}
13+
14+
public function setUpSlackMonolog()
15+
{
16+
logger()->setDefaultDriver('slack');
17+
ray()->disable();
18+
}
19+
20+
public function setUpRayLogger()
21+
{
22+
logger()->setDefaultDriver('null');
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
function monologDebug()
29+
{
30+
logger()->debug('Hello debug', [
31+
'foo' => 'bar'
32+
]);
33+
}
34+
35+
/** @test */
36+
function monologInfo()
37+
{
38+
logger()->info('Hello info', [
39+
'foo' => 'bar'
40+
]);
41+
}
42+
43+
/** @test */
44+
function monologWarning()
45+
{
46+
logger()->warning('Hello warning', [
47+
'foo' => 'bar'
48+
]);
49+
}
50+
51+
/** @test */
52+
function monologError()
53+
{
54+
logger()->error('Hello error', [
55+
'foo' => 'bar'
56+
]);
57+
}
58+
59+
/** @test */
60+
function monologCritical()
61+
{
62+
logger()->critical('Hello critical', [
63+
'foo' => 'bar'
64+
]);
65+
}
66+
67+
/** @test */
68+
function monologNotice()
69+
{
70+
logger()->notice('Hello notice', [
71+
'foo' => 'bar'
72+
]);
73+
}
74+
75+
/** @test */
76+
function monologAlert()
77+
{
78+
logger()->alert('Hello alert', [
79+
'foo' => 'bar'
80+
]);
81+
}
82+
83+
/** @test */
84+
function monologEmergency()
85+
{
86+
logger()->emergency('Hello emergency', [
87+
'foo' => 'bar'
88+
]);
89+
}
90+
91+
/** @test */
92+
function monologException()
93+
{
94+
try {
95+
throw new \Exception('Something went wrong');
96+
} catch (\Throwable $e) {
97+
logger()->error($e);
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)