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

GcmMessageTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testMutatorsAccessors() 0 13 1
A testInvalidKey() 0 4 1
A testDuplicatedKey() 0 5 1
A testJsonResult() 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\Adapter\Gcm;
11
12
use Jgut\Tify\Adapter\Gcm\GcmMessage;
13
14
/**
15
 * Custom Gcm message tests.
16
 */
17
class GcmMessageTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var \Jgut\Tify\Adapter\Gcm\GcmMessage
21
     */
22
    protected $message;
23
24
    public function setUp()
25
    {
26
        $this->message = new GcmMessage();
27
    }
28
29
    public function testMutatorsAccessors()
30
    {
31
        self::assertCount(0, $this->message->getNotificationPayload());
32
33
        $this->message->addNotificationPayload('first', 'first');
34
        self::assertCount(1, $this->message->getNotificationPayload());
35
36
        $this->message->setNotificationPayload(['first' => 'first', 'second' => 'second']);
37
        self::assertCount(2, $this->message->getNotificationPayload());
38
39
        $this->message->clearNotificationPayload();
40
        self::assertCount(0, $this->message->getNotificationPayload());
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function testInvalidKey()
47
    {
48
        $this->message->addNotificationPayload('   ', 'first');
49
    }
50
51
    /**
52
     * @expectedException \RuntimeException
53
     */
54
    public function testDuplicatedKey()
55
    {
56
        $this->message->addNotificationPayload('first', 'first');
57
        $this->message->addNotificationPayload('first', 'first');
58
    }
59
60
    public function testJsonResult()
61
    {
62
        $this->message->setRegistrationIds(['sdfshj']);
63
        $this->message->setCollapseKey('key');
64
        $this->message->setDelayWhileIdle(true);
65
        $this->message->setTimeToLive(600);
66
        $this->message->setRestrictedPackageName('package.name');
67
        $this->message->setDryRun(true);
68
        $this->message->setData(['key' => 'value']);
69
        $this->message->addNotificationPayload('first', 'first');
70
71
        $result = json_decode($this->message->toJson());
72
        self::assertTrue(isset($result->notification->first));
73
    }
74
}
75