Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Jan 28, 2025
1 parent 73f63ed commit ef47d7c
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.4'
coverage: none

- name: Install composer dependencies
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
},
"scripts": {
"x-ray": "vendor/bin/x-ray .",
"lint": "vendor/bin/php-cs-fixer fix -v",
"test:lint": "vendor/bin/php-cs-fixer fix -v --dry-run",
"lint": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix -v",
"test:lint": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix -v --dry-run",
"test:types": "vendor/bin/phpstan analyse --ansi --memory-limit=-1",
"test:unit": "vendor/bin/pest --colors=always --exclude-group=sandbox",
"test:sandbox": "vendor/bin/pest --colors=always --group=sandbox",
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/HasStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait HasStorage
{
public function storage(string $driver = null): StorageDriver
public function storage(string|null $driver = null): StorageDriver
{
$driver ??= config('telegraph.storage.default');

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Storable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface Storable
{
public function storage(string $driver = null): StorageDriver;
public function storage(string|null $driver = null): StorageDriver;

public function storageKey(): string|int;
}
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResultContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InlineQueryResultContact extends InlineQueryResult
protected string|null $thumbUrl = null;
protected string|null $parseMode = null;

public static function make(string $id, string $phoneNumber, string $firstName, string $message = null): InlineQueryResultContact
public static function make(string $id, string $phoneNumber, string $firstName, string|null $message = null): InlineQueryResultContact
{
$result = new InlineQueryResultContact();
$result->id = $id;
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResultLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InlineQueryResultLocation extends InlineQueryResult
protected float|null $horizontalAccuracy = null;
protected string|null $parseMode = null;

public static function make(string $id, string $title, float $latitude, float $longitude, string $message = null): InlineQueryResultLocation
public static function make(string $id, string $title, float $latitude, float $longitude, string|null $message = null): InlineQueryResultLocation
{
$result = new InlineQueryResultLocation();
$result->id = $id;
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResultVenue.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InlineQueryResultVenue extends InlineQueryResult
protected int|null $thumbWidth = null;
protected int|null $thumbHeight = null;

public static function make(string $id, string $title, float $latitude, float $longitude, string $address, string $message = null): InlineQueryResultVenue
public static function make(string $id, string $title, float $latitude, float $longitude, string $address, string|null $message = null): InlineQueryResultVenue
{
$result = new InlineQueryResultVenue();
$result->id = $id;
Expand Down
11 changes: 6 additions & 5 deletions src/Models/TelegraphBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
class TelegraphBot extends Model implements Storable
{
/** @use HasFactory<TelegraphBotFactory> */
use HasFactory;
use HasStorage;

Expand Down Expand Up @@ -72,7 +73,7 @@ public function getRouteKeyName(): string
return 'token';
}

public static function fromId(int $id = null): TelegraphBot
public static function fromId(int|null $id = null): TelegraphBot
{
if (empty($id)) {
/** @noinspection PhpIncompatibleReturnTypeInspection */
Expand All @@ -93,15 +94,15 @@ public static function fromToken(string $token): TelegraphBot
}

/**
* @return HasMany<TelegraphChat>
* @return HasMany<TelegraphChat, $this>
*/
public function chats(): HasMany
{
/** @phpstan-ignore-next-line */
return $this->hasMany(config('telegraph.models.chat'), 'telegraph_bot_id');
}

public function registerWebhook(bool $dropPendingUpdates = null, int $maxConnections = null, string $secretToken = null): Telegraph
public function registerWebhook(bool|null $dropPendingUpdates = null, int|null $maxConnections = null, string|null $secretToken = null): Telegraph
{
return TelegraphFacade::bot($this)->registerWebhook($dropPendingUpdates, $maxConnections, $secretToken);
}
Expand Down Expand Up @@ -167,7 +168,7 @@ public function getFileInfo(string $fileId): Telegraph
return TelegraphFacade::bot($this)->getFileInfo($fileId);
}

public function store(Downloadable|string $attachment, string $path, string $filename = null): string
public function store(Downloadable|string $attachment, string $path, string|null $filename = null): string
{
return TelegraphFacade::bot($this)->store($attachment, $path, $filename);
}
Expand All @@ -182,7 +183,7 @@ public function url(): string
*
* @return \Illuminate\Support\Collection<int, TelegramUpdate>
*/
public function updates(int $timeout = null, int $offset = null, int $limit = null, array $allowedUpdates = null): \Illuminate\Support\Collection
public function updates(int|null $timeout = null, int|null $offset = null, int|null $limit = null, array|null $allowedUpdates = null): \Illuminate\Support\Collection
{
$reply = TelegraphFacade::bot($this)->botUpdates($timeout, $offset, $limit, $allowedUpdates)->send();

Expand Down
27 changes: 14 additions & 13 deletions src/Models/TelegraphChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
class TelegraphChat extends Model implements Storable
{
/** @use HasFactory<TelegraphChatFactory> */
use HasFactory;
use HasStorage;

Expand Down Expand Up @@ -219,7 +220,7 @@ public function action(string $action): Telegraph
return TelegraphFacade::chat($this)->chatAction($action);
}

public function document(string $path, string $filename = null): Telegraph
public function document(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->document($path, $filename);
}
Expand All @@ -229,7 +230,7 @@ public function location(float $latitude, float $longitude): Telegraph
return TelegraphFacade::chat($this)->location(latitude: $latitude, longitude: $longitude);
}

public function photo(string $path, string $filename = null): Telegraph
public function photo(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->photo($path, $filename);
}
Expand All @@ -242,7 +243,7 @@ public function mediaGroup(array $media): Telegraph
return TelegraphFacade::chat($this)->mediaGroup($media);
}

public function sticker(string $path, string $filename = null): Telegraph
public function sticker(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->sticker($path, $filename);
}
Expand All @@ -252,22 +253,22 @@ public function venue(float $latitude, float $longitude, string $title, string $
return TelegraphFacade::chat($this)->venue($latitude, $longitude, $title, $address);
}

public function animation(string $path, string $filename = null): Telegraph
public function animation(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->animation($path, $filename);
}

public function video(string $path, string $filename = null): Telegraph
public function video(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->video($path, $filename);
}

public function audio(string $path, string $filename = null): Telegraph
public function audio(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->audio($path, $filename);
}

public function voice(string $path, string $filename = null): Telegraph
public function voice(string $path, string|null $filename = null): Telegraph
{
return TelegraphFacade::chat($this)->voice($path, $filename);
}
Expand Down Expand Up @@ -403,7 +404,7 @@ public function quiz(string $question): TelegraphQuizPayload
return TelegraphFacade::chat($this)->quiz($question);
}

public function dice(string $emoji = null): Telegraph
public function dice(string|null $emoji = null): Telegraph
{
return TelegraphFacade::chat($this)->dice($emoji);
}
Expand All @@ -423,27 +424,27 @@ public function setMenuButton(): SetChatMenuButtonPayload
return TelegraphFacade::chat($this)->setChatMenuButton();
}

public function createForumTopic(string $name, int $iconColor = null, string $iconCustomEmojiId = null): Telegraph
public function createForumTopic(string $name, int|null $iconColor = null, string|null $iconCustomEmojiId = null): Telegraph
{
return TelegraphFacade::chat($this)->createForumTopic($name, $iconColor, $iconCustomEmojiId);
}

public function editForumTopic(int $threadId = null, string $name = null, string $iconCustomEmojiId = null): Telegraph
public function editForumTopic(int|null $threadId = null, string|null $name = null, string|null $iconCustomEmojiId = null): Telegraph
{
return TelegraphFacade::chat($this)->editForumTopic($threadId, $name, $iconCustomEmojiId);
}

public function closeForumTopic(int $threadId = null): Telegraph
public function closeForumTopic(int|null $threadId = null): Telegraph
{
return TelegraphFacade::chat($this)->closeForumTopic($threadId);
}

public function reopenForumTopic(int $threadId = null): Telegraph
public function reopenForumTopic(int|null $threadId = null): Telegraph
{
return TelegraphFacade::chat($this)->reopenForumTopic($threadId);
}

public function deleteForumTopic(int $threadId = null): Telegraph
public function deleteForumTopic(int|null $threadId = null): Telegraph
{
return TelegraphFacade::chat($this)->deleteForumTopic($threadId);
}
Expand Down
10 changes: 5 additions & 5 deletions src/ScopedPayloads/TelegraphEditMediaPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TelegraphEditMediaPayload extends \DefStudio\Telegraph\Telegraph
{
use BuildsFromTelegraphClass;

public function photo(string $path, string $filename = null): self
public function photo(string $path, string|null $filename = null): self
{
$telegraph = clone $this;

Expand All @@ -29,7 +29,7 @@ public function photo(string $path, string $filename = null): self
return $telegraph;
}

public function document(string $path, string $filename = null): self
public function document(string $path, string|null $filename = null): self
{
$telegraph = clone $this;

Expand All @@ -48,7 +48,7 @@ public function document(string $path, string $filename = null): self
return $telegraph;
}

public function animation(string $path, string $filename = null): self
public function animation(string $path, string|null $filename = null): self
{
$telegraph = clone $this;

Expand All @@ -67,7 +67,7 @@ public function animation(string $path, string $filename = null): self
return $telegraph;
}

public function video(string $path, string $filename = null): self
public function video(string $path, string|null $filename = null): self
{
$telegraph = clone $this;

Expand All @@ -86,7 +86,7 @@ public function video(string $path, string $filename = null): self
return $telegraph;
}

public function audio(string $path, string $filename = null): self
public function audio(string $path, string|null $filename = null): self
{
$telegraph = clone $this;

Expand Down
26 changes: 13 additions & 13 deletions tests/Unit/Concerns/HasBotsAndChatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,31 @@
})->toMatchUtf8TelegramSnapshot();
});

test('photo is validated', function (string $path, bool $valid, string $exceptionClass = null, string $exceptionMessage = null, array $customConfigs = []) {
test('photo is validated', function (string $fileName, bool $valid, string $exceptionClass = null, string $exceptionMessage = null, array $customConfigs = []) {
foreach ($customConfigs as $key => $value) {
Config::set($key, $value);
}

if ($valid) {
expect(make_chat()->setChatPhoto(Storage::path($path)))
expect(make_chat()->setChatPhoto(Storage::path($fileName)))
->toBeInstanceOf(\DefStudio\Telegraph\Telegraph::class);
} else {
expect(fn () => make_chat()->photo(Storage::path($path)))
expect(fn () => make_chat()->photo(Storage::path($fileName)))
->toThrow($exceptionClass, $exceptionMessage);
}
})->with([
'valid' => [
'file' => 'photo.jpg',
'fileName' => 'photo.jpg',
'valid' => true,
],
'invalid weight' => [
'file' => 'invalid_photo_size.jpg',
'fileName' => 'invalid_photo_size.jpg',
'valid' => false,
'exception' => FileException::class,
'message' => 'Photo size (10.340000 Mb) exceeds max allowed size of 10.000000 MB',
],
'valid custom weight' => [
'file' => 'invalid_photo_size.jpg',
'fileName' => 'invalid_photo_size.jpg',
'valid' => true,
'exception' => null,
'message' => null,
Expand All @@ -156,7 +156,7 @@
],
],
'invalid custom weight' => [
'file' => 'photo.jpg',
'fileName' => 'photo.jpg',
'valid' => false,
'exception' => FileException::class,
'message' => 'Photo size (0.030000 Mb) exceeds max allowed size of 0.010000 MB',
Expand All @@ -165,13 +165,13 @@
],
],
'invalid ratio' => [
'file' => 'invalid_photo_ratio_thin.jpg',
'fileName' => 'invalid_photo_ratio_thin.jpg',
'valid' => false,
'exception' => FileException::class,
'message' => "Ratio of height and width (22.222222) exceeds max allowed ratio of 20.000000",
],
'valid custom ratio' => [
'file' => 'invalid_photo_ratio_thin.jpg',
'fileName' => 'invalid_photo_ratio_thin.jpg',
'valid' => true,
'exception' => null,
'message' => null,
Expand All @@ -180,7 +180,7 @@
],
],
'invalid custom ratio' => [
'file' => 'photo.jpg',
'fileName' => 'photo.jpg',
'valid' => false,
'exception' => FileException::class,
'message' => "Ratio of height and width (1.000000) exceeds max allowed ratio of 0.990000",
Expand All @@ -189,13 +189,13 @@
],
],
'invalid size' => [
'file' => 'invalid_photo_ratio_huge.jpg',
'fileName' => 'invalid_photo_ratio_huge.jpg',
'valid' => false,
'exception' => FileException::class,
'message' => 'Photo\'s sum of width and height (11000px) exceed allowed 10000px',
],
'valid custom size' => [
'file' => 'invalid_photo_ratio_huge.jpg',
'fileName' => 'invalid_photo_ratio_huge.jpg',
'valid' => true,
'exception' => null,
'message' => null,
Expand All @@ -204,7 +204,7 @@
],
],
'invalid custom size' => [
'file' => 'photo.jpg',
'fileName' => 'photo.jpg',
'valid' => false,
'exception' => FileException::class,
'message' => 'Photo\'s sum of width and height (800px) exceed allowed 799px',
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Storage/FileStoreDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use DefStudio\Telegraph\Models\TelegraphChat;
use DefStudio\Telegraph\Tests\Unit\Storage\TestStorable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

beforeEach(function () {
Expand Down

0 comments on commit ef47d7c

Please sign in to comment.