From a39765a98c7e698385746295a246529cd5452981 Mon Sep 17 00:00:00 2001 From: butschster Date: Tue, 23 Apr 2024 11:24:35 +0400 Subject: [PATCH] Adds random phrase generator --- app/Http/Controllers/CallAction.php | 10 +- app/Modules/Inspector/Common.php | 6 +- app/Modules/Monolog/Common.php | 44 +-- app/Modules/Profiler/Common.php | 4 +- app/Modules/Ray/RayCommon.php | 94 +++--- app/Modules/Ray/RayLaravel.php | 38 ++- app/Modules/Sentry/Common.php | 12 +- app/Modules/Smtp/Common.php | 9 +- app/Modules/VarDump/Common.php | 29 +- app/RandomPhraseGenerator.php | 496 ++++++++++++++++++++++++++++ 10 files changed, 631 insertions(+), 111 deletions(-) create mode 100644 app/RandomPhraseGenerator.php diff --git a/app/Http/Controllers/CallAction.php b/app/Http/Controllers/CallAction.php index 4716e6f..3ff1c12 100644 --- a/app/Http/Controllers/CallAction.php +++ b/app/Http/Controllers/CallAction.php @@ -1,4 +1,5 @@ 'monologException', ]; - public function __invoke(Request $request) + public function __invoke(Request $request, RandomPhraseGenerator $generator) { $this->setUpFaker(); @@ -65,14 +67,14 @@ public function __invoke(Request $request) foreach ($this->setUpMap as $a => $method) { if (Str::startsWith($action, $a)) { - call_user_func([$this, $method]); + call_user_func([$this, $method], $generator); break; } } foreach ($this->actionsMap as $a => $method) { if ($action === $a) { - call_user_func([$this, $method]); + call_user_func([$this, $method], $generator); return 'ok'; } } @@ -80,7 +82,7 @@ public function __invoke(Request $request) $method = Str::studly(Str::replace(':', '_', $action)); if (method_exists($this, $method)) { - call_user_func([$this, $method]); + call_user_func([$this, $method], $generator); return 'ok'; } diff --git a/app/Modules/Inspector/Common.php b/app/Modules/Inspector/Common.php index e92b84f..8efedcf 100644 --- a/app/Modules/Inspector/Common.php +++ b/app/Modules/Inspector/Common.php @@ -9,13 +9,13 @@ trait Common { - public function setUpInspector() + public function setUpInspector(): void { ray()->disable(); } /** @test */ - public function inspectorRequest() + public function inspectorRequest(): void { $request = Request::create('/inspector'); @@ -23,7 +23,7 @@ public function inspectorRequest() } /** @test */ - public function inspectorCommand() + public function inspectorCommand(): void { Artisan::call('inspector:test'); } diff --git a/app/Modules/Monolog/Common.php b/app/Modules/Monolog/Common.php index 44d0c34..9b6f8de 100644 --- a/app/Modules/Monolog/Common.php +++ b/app/Modules/Monolog/Common.php @@ -3,21 +3,23 @@ namespace App\Modules\Monolog; +use App\RandomPhraseGenerator; + trait Common { - public function setUpSocketMonolog() + public function setUpSocketMonolog(): void { logger()->setDefaultDriver('socket'); ray()->disable(); } - public function setUpSlackMonolog() + public function setUpSlackMonolog(): void { logger()->setDefaultDriver('slack'); ray()->disable(); } - public function setUpRayLogger() + public function setUpRayLogger(): void { logger()->setDefaultDriver('null'); } @@ -25,74 +27,74 @@ public function setUpRayLogger() /** * @test */ - function monologDebug() + function monologDebug(RandomPhraseGenerator $generator): void { - logger()->debug('Hello debug', [ + logger()->debug($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologInfo() + function monologInfo(RandomPhraseGenerator $generator): void { - logger()->info('Hello info', [ + logger()->info($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologWarning() + function monologWarning(RandomPhraseGenerator $generator): void { - logger()->warning('Hello warning', [ + logger()->warning($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologError() + function monologError(RandomPhraseGenerator $generator): void { - logger()->error('Hello error', [ + logger()->error($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologCritical() + function monologCritical(RandomPhraseGenerator $generator): void { - logger()->critical('Hello critical', [ + logger()->critical($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologNotice() + function monologNotice(RandomPhraseGenerator $generator): void { - logger()->notice('Hello notice', [ + logger()->notice($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologAlert() + function monologAlert(RandomPhraseGenerator $generator): void { - logger()->alert('Hello alert', [ + logger()->alert($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologEmergency() + function monologEmergency(RandomPhraseGenerator $generator): void { - logger()->emergency('Hello emergency', [ + logger()->emergency($generator->generate('Buggregator'), [ 'foo' => 'bar' ]); } /** @test */ - function monologException() + function monologException(RandomPhraseGenerator $generator): void { try { - throw new \Exception('Something went wrong'); + throw new \Exception($generator->generateException('Buggregator')); } catch (\Throwable $e) { logger()->error($e); } diff --git a/app/Modules/Profiler/Common.php b/app/Modules/Profiler/Common.php index ff176cf..ec49e68 100644 --- a/app/Modules/Profiler/Common.php +++ b/app/Modules/Profiler/Common.php @@ -5,14 +5,14 @@ trait Common { - public function setupProfiler() + public function setupProfiler(): void { ray()->disable(); logger()->setDefaultDriver('null'); } /** @test */ - function profilerReport() + function profilerReport(): void { } } diff --git a/app/Modules/Ray/RayCommon.php b/app/Modules/Ray/RayCommon.php index dc55d54..1067b65 100644 --- a/app/Modules/Ray/RayCommon.php +++ b/app/Modules/Ray/RayCommon.php @@ -1,66 +1,74 @@ newScreen(); } /** @test */ - function rayNewScreenWithName() + function rayNewScreenWithName(): void { ray()->newScreen('My debug screen'); } /** @test */ - function rayClearAll() + function rayClearAll(): void { ray()->clearAll(); } /** @test */ - function rayClearScreen() + function rayClearScreen(): void { ray()->clearScreen(); } /** @test */ - function rayInt() + function rayInt(): void { - ray(...range(0, 9)); + ray(4, 8, 15, 16, 23, 42); } /** @test */ - function rayString() + function rayString(RandomPhraseGenerator $generator): void { - ray('Hello', 'World'); + ray('Here is a random phrase', $generator->generate('Buggregator')); } /** @test */ - function rayArray() + function rayArray(): void { - ray(['a' => 1, 'b' => ['c' => 3]]); + ray(['a' => 4, 'b' => ['c' => 8, 'd' => 15], 'e' => [16, 23, 42]]); } /** @test */ - function rayBool() + function rayBool(): void { ray(true, false); } /** @test */ - function rayObject() + function rayObject(RandomPhraseGenerator $generator): void { + $object = new \stdClass(); + $object->name = 'Buggregator'; + $object->funnyFact = $generator->generate('Buggregator'); + ray($object); + ray(ray()); } /** @test */ - function rayColors() + function rayColors(): void { ray('this is green')->green(); ray('this is orange')->orange(); @@ -71,7 +79,7 @@ function rayColors() } /** @test */ - function raySizes() + function raySizes(): void { ray('small')->small(); ray('regular'); @@ -79,31 +87,31 @@ function raySizes() } /** @test */ - function rayLabels() + function rayLabels(): void { ray(['John', 'Paul', 'George', 'Ringo'])->label('Beatles'); } /** @test */ - function rayCaller() + function rayCaller(): void { ray()->caller(); } /** @test */ - function rayTrace() + function rayTrace(): void { ray()->trace(); } /** @test */ - function rayPause() + function rayPause(): void { ray()->pause(); } /** @test */ - function rayCounter() + function rayCounter(): void { foreach (range(1, 2) as $i) { ray()->count(); @@ -115,7 +123,7 @@ function rayCounter() } /** @test */ - function rayCounterWithName() + function rayCounterWithName(): void { foreach (range(1, 4) as $i) { ray()->count('first'); @@ -129,7 +137,7 @@ function rayCounterWithName() } /** @test */ - function rayLimit() + function rayLimit(): void { foreach (range(1, 10) as $i) { ray()->limit(3)->text("A #{$i}"); // counts to 3 @@ -139,13 +147,13 @@ function rayLimit() } /** @test */ - function rayClassName() + function rayClassName(): void { ray()->className($this); } /** @test */ - function rayMeasure() + function rayMeasure(): void { ray()->measure(); @@ -159,7 +167,7 @@ function rayMeasure() } /** @test */ - function rayJson() + function rayJson(): void { ray()->toJson(['a' => 1, 'b' => ['c' => 3]]); @@ -170,36 +178,36 @@ function rayJson() ray()->toJson( ['a' => 1, 'b' => ['c' => 3]], ['d' => ['e' => 5]], - $object + $object, ); ray()->json( - json_encode(['a' => 1, 'b' => ['c' => 3]]) + json_encode(['a' => 1, 'b' => ['c' => 3]]), ); } /** @test */ - function rayXml() + function rayXml(RandomPhraseGenerator $generator): void { ray()->xml( - '3' + ''.$generator->generate('Buggregator').'', ); } /** @test */ - function rayCarbon() + function rayCarbon(): void { ray()->carbon(new \Carbon\Carbon()); } /** @test */ - function rayFile() + function rayFile(): void { ray()->file(base_path('.env')); } /** @test */ - function rayTable() + function rayTable(): void { ray()->table([ 'First' => 'First value', @@ -211,55 +219,55 @@ function rayTable() } /** @test */ - function rayImage() + function rayImage(): void { ray()->image('https://placekitten.com/200/300'); } /** @test */ - function rayHtml() + function rayHtml(RandomPhraseGenerator $generator): void { - ray()->html('Bold string'); + ray()->html(''.$generator->generate('Buggregator').''); } /** @test */ - function rayText() + function rayText(RandomPhraseGenerator $generator): void { - ray()->text('this string is html encoded'); + ray()->text(''.$generator->generate('Buggregator').''); ray()->text(' whitespace formatting' . PHP_EOL . ' is preserved as well.'); } /** @test */ - function rayHide() + function rayHide(): void { ray($this)->hide(); } /** @test */ - function rayNotify() + function rayNotify(): void { ray()->notify('This is my notification'); } /** @test */ - function rayPhpinfo() + function rayPhpinfo(): void { ray()->phpinfo(); } /** @test */ - function rayException() + function rayException(RandomPhraseGenerator $generator): void { try { - throw new \Exception('Something went wrong'); + throw new \Exception($generator->generateException('Buggregator')); } catch (\Exception $e) { ray()->exception($e); } } /** @test */ - function rayMarkdown() + function rayMarkdown(RandomPhraseGenerator $generator): void { - ray()->markdown('# Hello World'); + ray()->markdown('# ' . $generator->generate('Buggregator')); } } diff --git a/app/Modules/Ray/RayLaravel.php b/app/Modules/Ray/RayLaravel.php index 320fd72..4c39f7c 100644 --- a/app/Modules/Ray/RayLaravel.php +++ b/app/Modules/Ray/RayLaravel.php @@ -1,4 +1,5 @@ showQueries(); User::firstWhere('email', 'john@example.com'); } /** @test */ - function rayCountQueries() + function rayCountQueries(): void { ray()->countQueries(function () { User::all(); @@ -30,7 +32,7 @@ function rayCountQueries() } /** @test */ - function rayManuallyShowedQuery() + function rayManuallyShowedQuery(): void { User::query() ->where('first_name', 'John') @@ -41,21 +43,21 @@ function rayManuallyShowedQuery() } /** @test */ - function rayShowEvents() + function rayShowEvents(): void { ray()->showEvents(); event(new ModelsPruned(new User(), 100)); } /** @test */ - function rayShowJobs() + function rayShowJobs(): void { ray()->showJobs(); dispatch(new TestJob('my-test-job')); } /** @test */ - function rayShowCache() + function rayShowCache(): void { ray()->showCache(); @@ -67,31 +69,31 @@ function rayShowCache() } /** @test */ - function rayShowHttpClientRequests() + function rayShowHttpClientRequests(): void { ray()->showHttpClientRequests(); Http::get('https://ya.ru', [ - 'heloo' => 'world' + 'heloo' => 'world', ]); } /** @test */ - function rayHandlingModels() + function rayHandlingModels(): void { ray()->model( - User::firstWhere('email', 'john@example.com') + User::firstWhere('email', 'john@example.com'), ); ray()->model(new User([ 'username' => 'john', - 'email' => 'john@example.com' + 'email' => 'john@example.com', ])); } /** @test */ - function rayMailable() + function rayMailable(RandomPhraseGenerator $generator): void { - $mail = new OrderShipped($this->faker->sentence); + $mail = new OrderShipped($generator->generateEmailSubject()); $mail->from($this->faker->email, 'Test from'); $mail->cc($this->faker->email); $mail->bcc($this->faker->email); @@ -101,15 +103,15 @@ function rayMailable() } /** @test */ - function rayShowViews() + function rayShowViews(RandomPhraseGenerator $generator): void { ray()->showViews(); - view('inspector', ['name' => 'John Doe'])->render(); + view('inspector', ['phrase' => $generator->generate('Buggregator')])->render(); } /** @test */ - function rayCollections() + function rayCollections(): void { collect(['a', 'b', 'c']) ->ray('original collection') // displays the original collection @@ -118,7 +120,7 @@ function rayCollections() } /** @test */ - function rayStrString() + function rayStrString(): void { Str::of('Lorem') ->append(' Ipsum') @@ -127,7 +129,7 @@ function rayStrString() } /** @test */ - function rayEnv() + function rayEnv(): void { ray()->env(); } diff --git a/app/Modules/Sentry/Common.php b/app/Modules/Sentry/Common.php index d44e188..bebf2ce 100644 --- a/app/Modules/Sentry/Common.php +++ b/app/Modules/Sentry/Common.php @@ -1,38 +1,40 @@ disable(); logger()->setDefaultDriver('null'); } /** @test */ - function sentryReport() + function sentryReport(RandomPhraseGenerator $generator): void { try { \Illuminate\Support\Facades\Artisan::call('migrate:fresh', ['--force' => true]); \Illuminate\Support\Facades\Artisan::call('db:seed', ['--force' => true]); - throw new \Exception('Something went wrong'); + throw new \Exception($generator->generateException('Buggregator')); } catch (\Throwable $e) { report($e); } } /** @test */ - function sentryEvent() + function sentryEvent(RandomPhraseGenerator $generator): void { \Illuminate\Support\Facades\Artisan::call('migrate:fresh', ['--force' => true]); \Illuminate\Support\Facades\Artisan::call('db:seed', ['--force' => true]); $currentHub = SentrySdk::getCurrentHub(); $client = $currentHub->getClient(); - $currentHub->captureMessage('This is a test message from the Sentry bundle'); + $currentHub->captureMessage($generator->generateException('Buggregator')); } } diff --git a/app/Modules/Smtp/Common.php b/app/Modules/Smtp/Common.php index e4c8a96..d662c0d 100644 --- a/app/Modules/Smtp/Common.php +++ b/app/Modules/Smtp/Common.php @@ -5,24 +5,25 @@ use App\Mail\OrderShipped; use App\Mail\WelcomeMail; +use App\RandomPhraseGenerator; use Illuminate\Support\Facades\Mail; trait Common { - public function setUpSmtp() + public function setUpSmtp(): void { ray()->disable(); } /** @test */ - function smtpOrderShipped() + function smtpOrderShipped(RandomPhraseGenerator $generator): void { Mail::to([$this->faker->email, $this->faker->email]) - ->send(new OrderShipped($this->faker->sentence)); + ->send(new OrderShipped($generator->generateEmailSubject())); } /** @test */ - function smtpWelcomeMail() + function smtpWelcomeMail(): void { Mail::to($this->faker->email)->send(new WelcomeMail()); } diff --git a/app/Modules/VarDump/Common.php b/app/Modules/VarDump/Common.php index 164bafc..5a8928e 100644 --- a/app/Modules/VarDump/Common.php +++ b/app/Modules/VarDump/Common.php @@ -1,13 +1,15 @@ disable(); @@ -17,40 +19,45 @@ public function setUpVarDumper() } /** @test */ - function varDumpString() + function varDumpString(RandomPhraseGenerator $generator): void { - dump('Hello', 'World'); + dump('Here is a random phrase', $generator->generate('Buggregator')); } /** @test */ - function varDumpArray() + function varDumpArray(): void { - dump(['a' => 1, 'b' => ['c' => 3]]); + dump(['a' => 4, 'b' => ['c' => 8, 'd' => 15], 'e' => [16, 23, 42]]); } /** @test */ - function varDumpBool() + function varDumpBool(): void { dump(true, false); } /** @test */ - function varDumpInt() + function varDumpInt(): void { - dump(1); + dump(4, 8, 15, 16, 23, 42); } /** @test */ - function varDumpObject() + function varDumpObject(RandomPhraseGenerator $generator): void { + $object = new \stdClass(); + $object->name = 'Buggregator'; + $object->funnyFact = $generator->generate('Buggregator'); + + dump($object); dump(ray()); } /** @test */ - function varDumpException() + function varDumpException(RandomPhraseGenerator $generator): void { try { - throw new \Exception('Something went wrong'); + throw new \Exception($generator->generateException('Buggregator')); } catch (\Exception $e) { dump($e); } diff --git a/app/RandomPhraseGenerator.php b/app/RandomPhraseGenerator.php new file mode 100644 index 0000000..55241b6 --- /dev/null +++ b/app/RandomPhraseGenerator.php @@ -0,0 +1,496 @@ +