-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for sending sms by faraz drier
- Loading branch information
Showing
2 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
convertDeprecationsToExceptions="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
stopOnFailure="false" | ||
> | ||
<testsuites> | ||
<testsuite name="SMS Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" processIsolation="false" bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="SMS Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Omalizadeh\Sms\Tests; | ||
|
||
|
||
use Illuminate\Support\Facades\Http; | ||
use Omalizadeh\Sms\Drivers\FarazSms\FarazSms; | ||
use Omalizadeh\Sms\Exceptions\SendingSmsFailedException; | ||
|
||
class FarazSmsTest extends TestCase | ||
{ | ||
protected FarazSms $farazSms; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
config(['sms.faraz_sms.api_key' => 'test_api_key']); | ||
|
||
$this->farazSms = new FarazSms(config('sms.faraz_sms')); | ||
} | ||
|
||
public function test_sms_can_be_sent_successfully_by_faraz_driver() | ||
{ | ||
Http::fake([ | ||
'https://api2.ippanel.com/api/v1/sms/send/webservice/single' => Http::response([ | ||
'status' => 'OK', | ||
'code' => 200, | ||
'data' => [ | ||
'message_id' => '123456789' | ||
], | ||
'error_message' => null | ||
], 200) | ||
]); | ||
|
||
$result = $this->farazSms->send('09123456789', 'Test message', ['sender' => '1000']); | ||
|
||
$this->assertEquals('123456789', $result->getMessageId()); | ||
|
||
Http::assertSent(function ($request) { | ||
return $request->url() == 'https://api2.ippanel.com/api/v1/sms/send/webservice/single' && | ||
$request['recipient'] == ['09123456789'] && | ||
$request['message'] == 'Test message' && | ||
$request['sender'] == '1000' && | ||
$request->header('apiKey')[0] == 'test_api_key'; | ||
}); | ||
} | ||
|
||
public function test_sms_can_get_failed_successfully() | ||
{ | ||
Http::fake([ | ||
'https://api2.ippanel.com/api/v1/sms/send/webservice/single' => Http::response([ | ||
'status' => 'error', | ||
'code' => 5, | ||
'message' => 'اعتبار کافی نیست.' | ||
], 200) | ||
]); | ||
|
||
$this->expectException(SendingSmsFailedException::class); | ||
$this->expectExceptionMessage('اعتبار کافی نیست.'); | ||
|
||
$this->farazSms->send('09123456789', 'Test message', ['sender' => '1000']); | ||
} | ||
|
||
public function test_invalid_response_structure_exception() | ||
{ | ||
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() | ||
{ | ||
$this->expectException(\Omalizadeh\Sms\Exceptions\InvalidParameterException::class); | ||
$this->expectExceptionMessage('sender parameter is required.'); | ||
|
||
$this->farazSms->send('09123456789', 'Test message'); | ||
} | ||
} |