Skip to content

Commit

Permalink
Add webAppData() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Sep 23, 2023
1 parent b2d2768 commit b8fbfb1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions src/Support/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Nutgram\Laravel\Support;

use SergiX44\Nutgram\Telegram\Web\WebAppData;


if (!function_exists(__NAMESPACE__.'\webAppData')) {
function webAppData(): ?WebAppData
{
return request()?->get('webAppData');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -24,6 +25,7 @@
$middleware = new ValidateWebAppData($this->bot);
$middleware->handle($this->request, function ($request) {
expect($request->get('webAppData'))->toBeInstanceOf(WebAppData::class);
expect(webAppData());
});
});

Expand Down

0 comments on commit b8fbfb1

Please sign in to comment.