Completed
Push — cake3 ( 9cfbb5...28240e )
by Romain
02:18
created

GcmComponentTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace ker0x\CakeGcm\Test\TestCase\Controller\Component;
3
4
use Cake\Controller\ComponentRegistry;
5
use Cake\Controller\Controller;
6
use Cake\Network\Request;
7
use Cake\Network\Response;
8
use Cake\TestSuite\IntegrationTestCase;
9
use ker0x\CakeGcm\Controller\Component\GcmComponent;
10
11
class GcmComponentTest extends IntegrationTestCase
12
{
13
    public $component = null;
14
15
    public $controller = null;
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
         // Setup our component and fake test controller
21
        $request = new Request();
22
        $response = new Response();
23
        $this->controller = $this->getMock(
24
            'Cake\Controller\Controller',
25
            null,
26
            [$request, $response]
27
        );
28
        $registry = new ComponentRegistry($this->controller);
29
        $this->component = new GcmComponent($registry, [
30
            'api' => [
31
                'key' => getenv('GCM_API_KEY')
32
            ],
33
            'http' => [
34
                'ssl_verify_peer' => false,
35
                'ssl_verify_peer_name' => false,
36
                'ssl_verify_host' => false
37
            ]
38
        ]);
39
    }
40
41
    public function testSendNotification()
42
    {
43
        $tokens = getenv('TOKEN');
44
45
        $result = $this->component->sendNotification(
46
            $tokens,
47
            [
48
                'title' => 'Hello World',
49
                'body' => 'My awesome Hello World!'
50
            ],
51
            [
52
                'dry_run' => true
53
            ]
54
        );
55
56
        $this->assertTrue($result);
57
    }
58
59
    public function testSendData()
60
    {
61
        $tokens = getenv('TOKEN');
62
63
        $result = $this->component->sendData(
64
            $tokens,
65
            [
66
                'data-1' => 'Lorem ipsum',
67
                'data-2' => 1234,
68
                'data-3' => true
69
            ],
70
            [
71
                'dry_run' => true
72
            ]
73
        );
74
75
        $this->assertTrue($result);
76
    }
77
78
    public function testResponse()
79
    {
80
        $tokens = getenv('TOKEN');
81
82
        $this->component->send(
83
            $tokens,
84
            [
85
                'notification' => [
86
                    'title' => 'Hello World',
87
                    'body' => 'My awesome Hello World!'
88
                ],
89
                'data' => [
90
                    'data-1' => 'Lorem ipsum',
91
                    'data-2' => 1234,
92
                    'data-3' => true
93
                ]
94
            ],
95
            [
96
                'delay_while_idle' => 'true',
97
                'time_to_live' => '60',
98
                'dry_run' => 'true'
99
            ]
100
        );
101
102
        $response = $this->component->response();
103
104
        $this->assertEquals(1, $response['success']);
105
        $this->assertEquals(0, $response['failure']);
106
    }
107
108
    public function tearDown()
109
    {
110
        parent::tearDown();
111
        // Clean up after we're done
112
        unset($this->component, $this->controller);
113
    }
114
}
115