Skip to content

Commit

Permalink
Add test for empty sender
Browse files Browse the repository at this point in the history
  • Loading branch information
omalizadeh committed Jul 9, 2024
1 parent 424a7a6 commit a93276a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/FarazSms/FarazSms.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function mergeSmsOptions(array $data, array $options): array
{
$sender = $options['sender'] ?? $this->getConfig('default_sender');

if (is_null($sender)) {
if (empty($sender)) {
throw new InvalidParameterException('sender parameter is required for Faraz sms driver.');
}

Expand Down
21 changes: 14 additions & 7 deletions tests/FarazSmsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Omalizadeh\Sms\Tests;


use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Omalizadeh\Sms\Drivers\FarazSms\FarazSms;
use Omalizadeh\Sms\Exceptions\SendingSmsFailedException;
Expand All @@ -20,7 +21,7 @@ protected function setUp(): void
$this->farazSms = new FarazSms(config('sms.faraz_sms'));
}

public function test_sms_can_be_sent_successfully_by_faraz_driver()
public function test_sms_can_be_sent_successfully_by_faraz_driver(): void
{
Http::fake([
'https://api2.ippanel.com/api/v1/sms/send/webservice/single' => Http::response([
Expand All @@ -30,7 +31,7 @@ public function test_sms_can_be_sent_successfully_by_faraz_driver()
'message_id' => '123456789'
],
'error_message' => null
], 200)
])
]);

$result = $this->farazSms->send('09123456789', 'Test message', ['sender' => '1000']);
Expand All @@ -46,14 +47,14 @@ public function test_sms_can_be_sent_successfully_by_faraz_driver()
});
}

public function test_sms_can_get_failed_successfully()
public function test_sms_can_get_failed_successfully(): void
{
Http::fake([
'https://api2.ippanel.com/api/v1/sms/send/webservice/single' => Http::response([
'status' => 'error',
'code' => 5,
'message' => 'اعتبار کافی نیست.'
], 200)
])
]);

$this->expectException(SendingSmsFailedException::class);
Expand All @@ -62,21 +63,27 @@ public function test_sms_can_get_failed_successfully()
$this->farazSms->send('09123456789', 'Test message', ['sender' => '1000']);
}

public function test_invalid_response_structure_exception()
public function test_invalid_response_structure_exception(): void
{
Http::fake([
'https://api2.ippanel.com/api/v1/sms/send/webservice/single' => Http::response([
'unexpected' => 'response'
], 200)
])
]);

$this->expectException(SendingSmsFailedException::class);

$this->farazSms->send('09123456789', 'Test message', ['sender' => '1000']);
}

public function test_missing_sender_option_leads_to_exception()
public function test_missing_sender_option_leads_to_exception(): void
{
config([
'sms.faraz_sms.default_sender' => '',
]);

$this->farazSms = new FarazSms(config('sms.faraz_sms'));

$this->expectException(\Omalizadeh\Sms\Exceptions\InvalidParameterException::class);
$this->expectExceptionMessage('sender parameter is required for Faraz sms driver.');

Expand Down

0 comments on commit a93276a

Please sign in to comment.