Completed
Push — master ( 020c5c...9dbce5 )
by Julián
08:49
created

MessageTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 8
c 4
b 1
f 0
lcom 1
cbo 2
dl 0
loc 113
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testDefaults() 0 8 1
A defaultParametersProvider() 0 7 1
A testMutators() 0 12 1
A testInvalidAPNSPayload() 0 6 1
A testInvalidGCMPayload() 0 6 1
A invalidGCMPayloadProvider() 0 18 1
A testPayload() 0 14 1
1
<?php
2
/**
3
 * Push notification services abstraction (http://github.com/juliangut/tify)
4
 *
5
 * @link https://github.com/juliangut/tify for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Tify\Tests\Message;
11
12
use Jgut\Tify\Message;
13
14
/**
15
 * Message tests.
16
 */
17
class MessageTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var \Jgut\Tify\Message
21
     */
22
    protected $message;
23
24
    public function setUp()
25
    {
26
        $this->message = new Message;
27
    }
28
29
    /**
30
     * @dataProvider defaultParametersProvider
31
     */
32
    public function testDefaults($parameter)
33
    {
34
        self::assertTrue($this->message->hasParameter($parameter));
35
        self::assertNull($this->message->getParameter($parameter));
36
37
        self::assertNull($this->message->getPayload('any_parameter'));
38
        self::assertEmpty($this->message->getPayloadData());
39
    }
40
41
    /**
42
     * Parameters provider
43
     *
44
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
45
     */
46
    public function defaultParametersProvider()
47
    {
48
        return [
49
            ['title'],
50
            ['body'],
51
        ];
52
    }
53
54
    public function testMutators()
55
    {
56
        $this->message->setTitle('message title');
57
        self::assertEquals('message title', $this->message->getParameter('title'));
58
59
        $this->message->setBody('message body');
60
        self::assertEquals('message body', $this->message->getParameter('body'));
61
62
        self::assertEquals('data_', $this->message->getPayloadPrefix());
63
        $this->message->setPayloadPrefix('');
64
        self::assertEquals('', $this->message->getPayloadPrefix());
65
    }
66
67
    /**
68
     * @expectedException \InvalidArgumentException
69
     */
70
    public function testInvalidAPNSPayload()
71
    {
72
        $this->message->setPayloadPrefix('');
73
74
        $this->message->setPayload('apc', 'value');
75
    }
76
77
    /**
78
     * @dataProvider invalidGCMPayloadProvider
79
     *
80
     * @param string $parameter
81
     *
82
     * @expectedException \InvalidArgumentException
83
     */
84
    public function testInvalidGCMPayload($parameter)
85
    {
86
        $this->message->setPayloadPrefix('');
87
88
        $this->message->setPayload($parameter, 'value');
89
    }
90
91
    /**
92
     * Payload provider.
93
     *
94
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
95
     */
96
    public function invalidGCMPayloadProvider()
97
    {
98
        return [
99
            [''],
100
            ['google'],
101
            ['google_param'],
102
            ['gcm'],
103
            ['gcm_param'],
104
            ['from'],
105
            ['collapse_key'],
106
            ['delay_while_idle'],
107
            ['time_to_live'],
108
            ['restricted_package_name'],
109
            ['dry_run'],
110
            ['priority'],
111
            ['content_available'],
112
        ];
113
    }
114
115
    public function testPayload()
116
    {
117
        $this->message->setPayload('first', true);
118
        self::assertTrue($this->message->hasPayload('first'));
119
        self::assertTrue($this->message->getPayload('first'));
120
        self::assertCount(1, $this->message->getPayloadData());
121
122
        $this->message->setPayloadData([
123
            'second' => 'second',
124
            'third' => 'third',
125
        ]);
126
        self::assertTrue($this->message->hasPayload('second'));
127
        self::assertCount(2, $this->message->getPayloadData());
128
    }
129
}
130