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\Tests\Mocks\MockSmsManager; |
9
|
|
|
use Tzsk\Sms\Tests\Mocks\Drivers\BarDriver; |
10
|
|
|
|
11
|
|
|
class SmsManagerTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function test_it_has_default_driver() |
14
|
|
|
{ |
15
|
|
|
$manager = new MockSmsManager(); |
16
|
|
|
|
17
|
|
|
$this->assertSameSize(config('sms'), $manager->getConfig()); |
18
|
|
|
$this->assertEquals(config('sms.default'), $manager->getDriver()); |
19
|
|
|
$this->assertSameSize($manager->getSettings(), config('sms.drivers.'.$manager->getDriver())); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function test_it_wont_accespt_wrong_driver() |
23
|
|
|
{ |
24
|
|
|
$this->expectException(\Exception::class); |
25
|
|
|
$manager = (new MockSmsManager())->via('foo'); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function test_driver_can_be_changed() |
29
|
|
|
{ |
30
|
|
|
$gateway = 'twilio'; |
31
|
|
|
$manager = (new MockSmsManager())->via($gateway); |
32
|
|
|
|
33
|
|
|
$this->assertEquals($gateway, $manager->getDriver()); |
34
|
|
|
$this->assertSameSize($manager->getSettings(), config('sms.drivers.'.$gateway)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function test_it_has_proper_driver_instance() |
38
|
|
|
{ |
39
|
|
|
$manager = new MockSmsManager(); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(Driver::class, $manager->driverInstance()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function test_can_call_directly() |
45
|
|
|
{ |
46
|
|
|
$response = (new MockSmsManager())->via('bar') |
47
|
|
|
->send('foo', function ($message) { |
48
|
|
|
$message->to(['baz']); |
49
|
|
|
}); |
50
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
51
|
|
|
$this->assertEquals('foo', $response->getBody()); |
52
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function test_can_call_from_facade() |
56
|
|
|
{ |
57
|
|
|
$response = Sms::via('bar')->send('foo', function ($m) { |
58
|
|
|
$m->to('baz'); |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
62
|
|
|
$this->assertEquals('foo', $response->getBody()); |
63
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function test_can_be_sent_by_dispatch_method() |
67
|
|
|
{ |
68
|
|
|
$response = Sms::via('bar')->send('foo')->to('baz')->dispatch(); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
71
|
|
|
$this->assertEquals('foo', $response->getBody()); |
72
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
public function test_sms_builder_can_be_sent() |
76
|
|
|
{ |
77
|
|
|
$response = Sms::send((new SmsBuilder)->via('bar')->to('baz')->send('foo')); |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
80
|
|
|
$this->assertEquals('foo', $response->getBody()); |
81
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function test_sms_builder_via_can_be_sent(Type $var = null) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$response = Sms::via('bar')->send((new SmsBuilder)->to('baz')->send('foo')); |
87
|
|
|
|
88
|
|
|
$this->assertInstanceOf(BarDriver::class, $response); |
89
|
|
|
$this->assertEquals('foo', $response->getBody()); |
90
|
|
|
$this->assertContains('baz', $response->getRecipients()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.