Completed
Push — master ( f47fb6...c9af04 )
by Julián
02:24
created

MessageTest::testInvalidParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
    public function testDefaults()
30
    {
31
        self::assertNull($this->message->getPayload('any_parameter'));
32
        self::assertEmpty($this->message->getPayloadData());
33
    }
34
35
    public function testMutators()
36
    {
37
        $this->message->setTitle('message title');
38
        self::assertTrue($this->message->hasParameter('title'));
39
        self::assertEquals('message title', $this->message->getParameter('title'));
40
41
        $this->message->setBody('message body');
42
        self::assertTrue($this->message->hasParameter('body'));
43
        self::assertEquals('message body', $this->message->getParameter('body'));
44
45
        self::assertEquals('data_', $this->message->getPayloadPrefix());
46
        $this->message->setPayloadPrefix('');
47
        self::assertEquals('', $this->message->getPayloadPrefix());
48
    }
49
50
    /**
51
     * @expectedException \InvalidArgumentException
52
     */
53
    public function testInvalidParameter()
54
    {
55
        $this->message->setParameter('made-up-parameter', true);
56
    }
57
58
    /**
59
     * @expectedException \InvalidArgumentException
60
     */
61
    public function testInvalidAPNSPayload()
62
    {
63
        $this->message->setPayloadPrefix('');
64
65
        $this->message->setPayload('apc', 'value');
66
    }
67
68
    /**
69
     * @dataProvider invalidGCMPayloadProvider
70
     *
71
     * @param string $parameter
72
     *
73
     * @expectedException \InvalidArgumentException
74
     */
75
    public function testInvalidGCMPayload($parameter)
76
    {
77
        $this->message->setPayloadPrefix('');
78
79
        $this->message->setPayload($parameter, 'value');
80
    }
81
82
    /**
83
     * Payload provider.
84
     *
85
     * @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...
86
     */
87
    public function invalidGCMPayloadProvider()
88
    {
89
        return [
90
            [''],
91
            ['google'],
92
            ['google_param'],
93
            ['gcm'],
94
            ['gcm_param'],
95
            ['from'],
96
            ['collapse_key'],
97
            ['delay_while_idle'],
98
            ['time_to_live'],
99
            ['restricted_package_name'],
100
            ['dry_run'],
101
            ['priority'],
102
            ['content_available'],
103
        ];
104
    }
105
106
    public function testPayload()
107
    {
108
        $this->message->setPayload('first', true);
109
        self::assertTrue($this->message->hasPayload('first'));
110
        self::assertTrue($this->message->getPayload('first'));
111
        self::assertCount(1, $this->message->getPayloadData());
112
113
        $this->message->setPayloadData([
114
            'second' => 'second',
115
            'third' => 'third',
116
        ]);
117
        self::assertTrue($this->message->hasPayload('second'));
118
        self::assertCount(2, $this->message->getPayloadData());
119
    }
120
}
121