Skip to content

Commit

Permalink
remove token exception from singleton (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
phattarachai authored Nov 22, 2022
1 parent 3c2a709 commit 36e5915
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"platform-check": false
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
2 changes: 1 addition & 1 deletion src/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Line
{
protected Client $client;
protected string $token;
protected ?string $token;
protected ?string $imageUrl = null;
protected ?string $imagePath = null;
protected ?string $stickerId = null;
Expand Down
31 changes: 30 additions & 1 deletion tests/LineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ protected function setUp(): void
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();

$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);
}

public function test_send_message(): void
{
$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);

$this->line->send('ทดสอบ');
self::assertTrue(true);
}

public function test_send_image_from_url_with_thumbnail_url(): void
{
$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);

$this->line->thumbnailUrl('https://phattarachai.dev/images/logo-purple.png')
->imageUrl('https://me.phattarachai.dev/wp-content/uploads/2021/02/laravel8-1.jpg')
->send('ข้อความ, thumbnail, และ Image');
Expand All @@ -37,6 +40,8 @@ public function test_send_image_from_url_with_thumbnail_url(): void

public function test_send_image_from_url_without_thumbnail_url(): void
{
$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);

$this->line->imageUrl('https://me.phattarachai.dev/wp-content/uploads/2021/02/laravel8-1.jpg')
->send('ข้อความ และ Image');

Expand All @@ -45,6 +50,8 @@ public function test_send_image_from_url_without_thumbnail_url(): void

public function test_upload_image(): void
{
$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);

$this->line->imagePath(__DIR__ . '/../art/line-notify-banner.jpg')
->send('ข้อความ และ Upload Image');

Expand All @@ -53,6 +60,8 @@ public function test_upload_image(): void

public function test_send_sticker(): void
{
$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);

$this->line->sticker(1, 138)
->send('ข้อความ และ Sticker');

Expand All @@ -61,10 +70,30 @@ public function test_send_sticker(): void

public function test_disable_notification(): void
{
$this->line = new Line($_ENV['LINE_ACCESS_TOKEN']);

$this->line->disableNotification()
->send('ข้อความไม่แจ้งเตือน');

self::assertTrue(true);
}

public function test_no_token_in_env(): void
{
new Line;

self::assertTrue(true);
}

public function test_send_with_no_token(): void
{
$this->expectExceptionMessage('Please specify line-notify access token');

$line = new Line;
$line->send('Should not be sent');

self::assertTrue(true);
}


}

0 comments on commit 36e5915

Please sign in to comment.