Last active
October 27, 2022 07:33
-
-
Save orobogenius/864afd83ea1817c107161f1635fd5c8a to your computer and use it in GitHub Desktop.
Test to verify that the custom component is able to use multiple drivers.
This file contains hidden or 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
<?php | |
namespace Tests\Unit; | |
use SMS; | |
use Tests\TestCase; | |
use App\Components\Sms\Drivers\NexmoDriver; | |
use App\Components\Sms\Drivers\TwilioDriver; | |
use App\Components\Sms\Drivers\NullDriver; | |
use App\Components\Sms\Contracts\SMS as SmsContract; | |
class SmsTest extends TestCase | |
{ | |
/** @test */ | |
public function component_can_be_extended_to_create_custom_drivers() | |
{ | |
SMS::extend('foo', function ($app) { | |
return new FooSmsDriver('dependency'); | |
}); | |
$fooDriver = SMS::channel('foo'); | |
$this->assertInstanceOf(FooSmsDriver::class, $fooDriver); | |
$this->assertEquals('Sent message from custom driver', $fooDriver->send()); | |
} | |
/** @test */ | |
public function component_can_use_multiple_drivers() | |
{ | |
$nexmoDriver = SMS::channel('nexmo'); | |
$this->assertInstanceOf(NexmoDriver::class, $nexmoDriver); | |
$twilioDriver = SMS::channel('twilio'); | |
$this->assertInstanceOf(TwilioDriver::class, $twilioDriver); | |
$nullDriver = SMS::channel('null'); | |
$this->assertInstanceOf(NullDriver::class, $nullDriver); | |
} | |
} | |
class FooSmsDriver implements SmsContract | |
{ | |
protected $someDependency; | |
public function __construct($dependency) | |
{ | |
$this->someDependency = $dependency; | |
} | |
public function send() | |
{ | |
return 'Sent message from custom driver'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment