1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tzsk\Sms\Tests; |
4
|
|
|
|
5
|
|
|
use Tzsk\Sms\Facade\Sms; |
6
|
|
|
use Tzsk\Sms\SmsBuilder; |
7
|
|
|
use Tzsk\Sms\Abstracts\Driver; |
8
|
|
|
use Tzsk\Sms\Drivers\Textlocal; |
9
|
|
|
use Tzsk\Sms\Tests\Mocks\MockSmsManager; |
10
|
|
|
use Tzsk\Sms\Tests\Mocks\Drivers\BarDriver; |
11
|
|
|
|
12
|
|
|
class SmsManagerTest extends TestCase |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
public function test_it_has_default_driver() |
15
|
|
|
{ |
16
|
|
|
$manager = new MockSmsManager(); |
17
|
|
|
|
18
|
|
|
$this->assertArraySubset(config('sms'), $manager->getConfig()); |
19
|
|
|
$this->assertEquals(config('sms.default'), $manager->getDriver()); |
20
|
|
|
$this->assertArraySubset($manager->getSettings(), config('sms.drivers.'.$manager->getDriver())); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function test_it_wont_accespt_wrong_driver() |
24
|
|
|
{ |
25
|
|
|
$this->expectException(\Exception::class); |
26
|
|
|
$manager = (new MockSmsManager())->via('foo'); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function test_driver_can_be_changed() |
30
|
|
|
{ |
31
|
|
|
$gateway = 'twilio'; |
32
|
|
|
$manager = (new MockSmsManager())->via($gateway); |
33
|
|
|
|
34
|
|
|
$this->assertEquals($gateway, $manager->getDriver()); |
35
|
|
|
$this->assertArraySubset($manager->getSettings(), config('sms.drivers.'.$gateway)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function test_it_has_proper_driver_instance() |
39
|
|
|
{ |
40
|
|
|
$manager = new MockSmsManager(); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf(Driver::class, $manager->driverInstance()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function test_can_call_directly() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$response = (new MockSmsManager())->via('bar') |
48
|
|
|
->send('foo', function ($message) { |
49
|
|
|
$message->to(['baz']); |
50
|
|
|
}); |
51
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
52
|
|
|
$this->assertEquals('foo', $response->getBody()); |
53
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function test_can_call_from_facade() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$response = Sms::via('bar')->send('foo', function ($m) { |
59
|
|
|
$m->to('baz'); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
63
|
|
|
$this->assertEquals('foo', $response->getBody()); |
64
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function test_can_be_sent_by_dispatch_method() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$response = Sms::via('bar')->send('foo')->to('baz')->dispatch(); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
72
|
|
|
$this->assertEquals('foo', $response->getBody()); |
73
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function test_sms_builder_can_be_sent() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
$response = Sms::send((new SmsBuilder)->via('bar')->to('baz')->send('foo')); |
79
|
|
|
|
80
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
81
|
|
|
$this->assertEquals('foo', $response->getBody()); |
82
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function test_sms_builder_via_can_be_sent(Type $var = null) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$response = Sms::via('bar')->send((new SmsBuilder)->to('baz')->send('foo')); |
88
|
|
|
|
89
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
90
|
|
|
$this->assertEquals('foo', $response->getBody()); |
91
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|