Completed
Push — master ( b912bc...bac835 )
by Kazi Mainuddin
01:57
created

test_can_be_sent_by_dispatch_method()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
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');
0 ignored issues
show
Unused Code introduced by
$manager is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $var is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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