SmsManagerTest::test_sms_builder_via_can_be_sent()   A
last analyzed

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 1
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
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...
12
{
13
    public function test_it_has_default_driver()
14
    {
15
        $manager = new MockSmsManager();
16
17
        $this->assertSameSize(config('sms'), $manager->getConfig());
0 ignored issues
show
Documentation introduced by
$manager->getConfig() is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
18
        $this->assertEquals(config('sms.default'), $manager->getDriver());
19
        $this->assertSameSize($manager->getSettings(), config('sms.drivers.'.$manager->getDriver()));
0 ignored issues
show
Documentation introduced by
$manager->getSettings() is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
20
    }
21
22
    public function test_it_wont_accespt_wrong_driver()
23
    {
24
        $this->expectException(\Exception::class);
25
        $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...
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));
0 ignored issues
show
Documentation introduced by
$manager->getSettings() is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
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...
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