Skip to content

Commit

Permalink
Merge pull request #15 from nutgram/webapp-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 authored Sep 23, 2023
2 parents 11eb592 + fe8e850 commit 36f763e
Show file tree
Hide file tree
Showing 3 changed files with 24 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,11 +6,13 @@
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 */
$this->bot = app(Nutgram::class);
$this->request = new Request();
$this->app->bind('request', fn () => $this->request);
});

it('validates web app data', function () {
Expand All @@ -24,6 +26,7 @@
$middleware = new ValidateWebAppData($this->bot);
$middleware->handle($this->request, function ($request) {
expect($request->get('webAppData'))->toBeInstanceOf(WebAppData::class);
expect(webAppData())->toBeInstanceOf(WebAppData::class);
});
});

Expand Down

0 comments on commit 36f763e

Please sign in to comment.