From b8fbfb1800b0aa39889b448c19e26071e9dc94a1 Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Sat, 23 Sep 2023 16:48:54 +0200 Subject: [PATCH 1/2] Add webAppData() helper --- composer.json | 10 ++++++++-- src/Support/Helpers.php | 13 +++++++++++++ ...iddlewareTest.php => ValidateWebAppDataTest.php} | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/Support/Helpers.php rename tests/Feature/{MiddlewareTest.php => ValidateWebAppDataTest.php} (95%) diff --git a/composer.json b/composer.json index 2726020..d67a921 100644 --- a/composer.json +++ b/composer.json @@ -43,12 +43,18 @@ "autoload": { "psr-4": { "Nutgram\\Laravel\\": "src/" - } + }, + "files": [ + "src/Support/Helpers.php" + ] }, "autoload-dev": { "psr-4": { "Nutgram\\Laravel\\Tests\\": "tests/" - } + }, + "files": [ + "src/Support/Helpers.php" + ] }, "extra": { "laravel": { diff --git a/src/Support/Helpers.php b/src/Support/Helpers.php new file mode 100644 index 0000000..dd8fb8c --- /dev/null +++ b/src/Support/Helpers.php @@ -0,0 +1,13 @@ +get('webAppData'); + } +} diff --git a/tests/Feature/MiddlewareTest.php b/tests/Feature/ValidateWebAppDataTest.php similarity index 95% rename from tests/Feature/MiddlewareTest.php rename to tests/Feature/ValidateWebAppDataTest.php index 0e6414a..e368571 100644 --- a/tests/Feature/MiddlewareTest.php +++ b/tests/Feature/ValidateWebAppDataTest.php @@ -6,6 +6,7 @@ use SergiX44\Nutgram\Telegram\Web\WebAppData; use SergiX44\Nutgram\Testing\FakeNutgram; use Symfony\Component\HttpKernel\Exception\HttpException; +use function Nutgram\Laravel\Support\webAppData; beforeEach(function () { /** @var FakeNutgram $bot */ @@ -24,6 +25,7 @@ $middleware = new ValidateWebAppData($this->bot); $middleware->handle($this->request, function ($request) { expect($request->get('webAppData'))->toBeInstanceOf(WebAppData::class); + expect(webAppData()); }); }); From fe8e8509fc99c84006f53e41b18d7dbeab2045be Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Sat, 23 Sep 2023 17:03:48 +0200 Subject: [PATCH 2/2] Fix test --- tests/Feature/ValidateWebAppDataTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Feature/ValidateWebAppDataTest.php b/tests/Feature/ValidateWebAppDataTest.php index e368571..b5156e2 100644 --- a/tests/Feature/ValidateWebAppDataTest.php +++ b/tests/Feature/ValidateWebAppDataTest.php @@ -12,6 +12,7 @@ /** @var FakeNutgram $bot */ $this->bot = app(Nutgram::class); $this->request = new Request(); + $this->app->bind('request', fn () => $this->request); }); it('validates web app data', function () { @@ -25,7 +26,7 @@ $middleware = new ValidateWebAppData($this->bot); $middleware->handle($this->request, function ($request) { expect($request->get('webAppData'))->toBeInstanceOf(WebAppData::class); - expect(webAppData()); + expect(webAppData())->toBeInstanceOf(WebAppData::class); }); });