DeviceEntityTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testUuid() 0 4 1
A testToken() 0 5 1
A testBadToken() 0 4 1
A testPlatform() 0 14 1
A testBadPlatform() 0 4 1
A testSerialize() 0 13 1
1
<?php
2
/**
3
 * Push notification server example (http://github.com/juliangut/tify_example)
4
 *
5
 * @link https://github.com/juliangut/tify_example for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify_example/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Pusher\Tests\Entity;
11
12
use Jgut\Pusher\Entity\DeviceEntity;
13
14
/**
15
 * Class DeviceEntityTest
16
 */
17
class DeviceEntityTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var DeviceEntity
21
     */
22
    protected $entity;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function setUp()
28
    {
29
        $this->entity = new DeviceEntity;
30
    }
31
32
    public function testUuid()
33
    {
34
        self::assertNull($this->entity->getUuid());
35
    }
36
37
    public function testToken()
38
    {
39
        $this->entity->setToken('aaa111bbb222ccc333');
40
        self::assertEquals('aaa111bbb222ccc333', $this->entity->getToken());
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function testBadToken()
47
    {
48
        $this->entity->setToken('@');
49
    }
50
51
    public function testPlatform()
52
    {
53
        $this->entity->setPlatform(DeviceEntity::PLATFORM_ANDROID);
54
        self::assertEquals(DeviceEntity::PLATFORM_ANDROID, $this->entity->getPlatform());
55
56
        $this->entity->setPlatform(DeviceEntity::PLATFORM_IOS);
57
        self::assertEquals(DeviceEntity::PLATFORM_IOS, $this->entity->getPlatform());
58
59
        $this->entity->setPlatform('android');
60
        self::assertEquals(DeviceEntity::PLATFORM_ANDROID, $this->entity->getPlatform());
61
62
        $this->entity->setPlatform('ios');
63
        self::assertEquals(DeviceEntity::PLATFORM_IOS, $this->entity->getPlatform());
64
    }
65
66
    /**
67
     * @expectedException \InvalidArgumentException
68
     */
69
    public function testBadPlatform()
70
    {
71
        $this->entity->setPlatform('windows');
72
    }
73
74
    public function testSerialize()
75
    {
76
        $this->entity->setToken('aaa111bbb222ccc333');
77
        $this->entity->setPlatform(DeviceEntity::PLATFORM_ANDROID);
78
79
        $serializable = $this->entity->jsonSerialize();
80
81
        self::assertTrue(array_key_exists('uuid', $serializable));
82
        self::assertTrue(array_key_exists('token', $serializable));
83
        self::assertEquals('aaa111bbb222ccc333', $serializable['token']);
84
        self::assertTrue(array_key_exists('platform', $serializable));
85
        self::assertEquals('android', $serializable['platform']);
86
    }
87
}
88