MessageTest::test_get_encrypted_segments()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Fhp\Message;
4
5
use Fhp\DataTypes\Kik;
6
use Fhp\DataTypes\Ktv;
7
use Fhp\Segment\AbstractSegment;
8
use Fhp\Segment\HKSAL;
9
use Fhp\Segment\HNHBS;
10
use Fhp\Segment\HNSHA;
11
use Fhp\Segment\HNSHK;
12
use Fhp\Segment\HNVSD;
13
use Fhp\Segment\HNVSK;
14
15
class MessageTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function test_setter_and_getter()
18
    {
19
        $message = new Message('12345678', 'username', '1234', '987654');
20
21
        $message->setDialogId(333);
22
        $this->assertEquals(333, $message->getDialogId());
23
24
        $message->setMessageNumber(10);
25
        $this->assertEquals(10, $message->getMessageNumber());
26
27
        $segments = $message->getSegments();
28
29
        $this->assertInternalType('array', $segments);
30
        $this->assertCount(3, $segments);
31
    }
32
33
    public function test_basic_message_creation()
34
    {
35
        $message = new Message('12345678', 'username', '1234', '987654');
36
        $date = new \DateTime();
37
        $dateString = $date->format('Ymd');
38
39
        $this->assertRegExp(
40
            '/HNHBK:1:3\+000000000296\+300\+0\+0\'HNVSK:998:3\+PIN:1\+998\+1\+1::987654\+1:' . $dateString
41
            . ':(\d+)\+2:2:13:@8@00000000:5:1\+280:12345678:username:V:0:0\+0\'HNVSD:999:1\+@130@HNSHK:2:4\+PIN:1'
42
            . '\+999\+(\d+)\+1\+1\+1::987654\+1\+1:' . $dateString . ':(\d+)\+1:999:1\+6:10:16\+280:12345678:'
43
            . 'username:S:0:0\'HNSHA:3:2\+(\d+)\+\+1234\'\'HNHBS:4:1\+0\'/',
44
            (string) $message
45
        );
46
    }
47
48
    public function test_message_creation_with_options_and_segments()
49
    {
50
        $kik = new Kik('290', '123123');
51
        $ktv = new Ktv('123123123', 'sub', $kik);
52
        $hksal = new HKSAL(HKSAL::VERSION, 3, $ktv, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

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...
53
        $options = array(
54
            Message::OPT_PINTAN_MECH => array('998')
55
        );
56
57
        $message = new Message(
58
            '12345678',
59
            'username',
60
            '1234',
61
            '987654',
62
            0,
63
            0,
64
            array($hksal),
65
            $options
66
        );
67
68
        $date = new \DateTime();
69
        $dateString = $date->format('Ymd');
70
71
        $this->assertRegExp(
72
            '/HNHBK:1:3\+000000000333\+300\+0\+0\'HNVSK:998:3\+PIN:2\+998\+1\+1::987654\+1:' . $dateString
73
            . ':(\d+)\+2:2:13:@8@00000000:5:1\+280:12345678:username:V:0:0\+0\'HNVSD:999:1\+@167@HNSHK:2:4\+PIN:2\+'
74
            . '998\+(\d+)\+1\+1\+1::987654\+1\+1:' . $dateString . ':(\d+)\+1:999:1\+6:10:16\+280:12345678:username:'
75
            . 'S:0:0\'HKSAL:3:7\+123123123:sub:290:123123\+1\'HNSHA:4:2\+(\d+)\+\+1234\'\'HNHBS:5:1\+0\'/',
76
            (string) $message
77
        );
78
    }
79
80
    public function test_get_encrypted_segments()
81
    {
82
        $message = new Message('12345678', 'username', '1234', '987654');
83
        $segments = $message->getEncryptedSegments();
84
85
        $this->assertInternalType('array', $segments);
86
87
        foreach ($segments as $segment) {
88
            $this->assertInstanceOf('\Fhp\Segment\AbstractSegment', $segment);
89
        }
90
    }
91
}