Completed
Push — master ( d77182...b3448d )
by Keal
02:40
created

SmsTest::testSetData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Odeen
5
 * Date: 2016/6/12
6
 * Time: 10:11
7
 */
8
9
namespace Sms\Test;
10
11
use LaravelSms\sms\Sms;
12
use PHPUnit_Framework_TestCase;
13
use Mockery as m;
14
15
class SmsTest extends PHPUnit_Framework_TestCase
16
{
17
    protected $sms = null;
18
19
    public function setUp()
20
    {
21
        $config = 'YunTongXun';
22
        $this->sms = new Sms($config);
23
    }
24
25
    public function testGetSmsData()
26
    {
27
        $data = $this->sms->getData();
28
        $this->assertArrayHasKey('to', $data);
29
        $this->assertArrayHasKey('templates', $data);
30
        $this->assertArrayHasKey('templateData', $data);
31
        $this->assertArrayHasKey('content', $data);
32
        $this->sms->to('...');
33
        $this->assertEquals('...', $this->sms->getData('to'));
34
    }
35
36
    public function smsData()
37
    {
38
        return $this->sms->getData();
39
    }
40
41
    public function testSetTo()
42
    {
43
        $this->sms->to('123456...');
44
        $smsData = $this->smsData();
45
        $this->assertEquals('123456...',$smsData['to']);
46
    }
47
48
    public function testSetContent()
49
    {
50
        $this->sms->content('this is content');
51
        $smsData = $this->smsData();
52
        $this->assertEquals('this is content', $smsData['content']);
53
    }
54
55
    public function testSetTemplate()
56
    {
57
        $this->sms->template('foo', '111');
58
        $smsData = $this->smsData();
59
        $this->assertEquals(['foo'=>'111'], $smsData['templates']);
60
61
        $this->sms->template(['foo'=>'111', 'bar'=>'222']);
0 ignored issues
show
Documentation introduced by
array('foo' => '111', 'bar' => '222') is of type array<string,string,{"fo...tring","bar":"string"}>, but the function expects a string.

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...
62
        $smsData = $this->smsData();
63
        $this->assertEquals(['foo'=>'111', 'bar'=>'222'], $smsData['templates']);
64
    }
65
66
    public function testSetData()
67
    {
68
        $this->sms->data([
69
            'code' => '1',
70
            'msg'  => 'msg',
71
        ]);
72
        $smsData = $this->smsData();
73
        $this->assertEquals([
74
            'code' => '1',
75
            'msg'  => 'msg',
76
        ], $smsData['templateData']);
77
    }
78
}