NotificationResponseTest::testRecipientsCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Level51\OneSignal;
4
5
use SilverStripe\Dev\SapphireTest;
6
7
class NotificationResponseTest extends SapphireTest
8
{
9
10
    /**
11
     * @var array
12
     * @see https://documentation.onesignal.com/reference/create-notification#results---create-notification
13
     */
14
    private $ok_payload = [
15
        'id'          => 'b98881cc-1e94-4366-bbd9-db8f3429292b',
16
        'recipients'  => 1,
17
        'external_id' => null
18
    ];
19
20
    public function testConstruct()
21
    {
22
        $raw = [];
23
        $response = new NotificationResponse($raw);
24
25
        $this->assertEquals(NotificationResponse::ACTION_CREATE, $response->getAction());
26
        $this->assertEquals($raw, $response->getRawResponsePayload());
27
    }
28
29
    public function testIsError()
30
    {
31
        $raw = [
32
            'errors' => [
33
                'contents must be key/value collections by language code'
34
            ]
35
        ];
36
        $response = new NotificationResponse($raw);
37
38
        $this->assertTrue($response->isError());
39
    }
40
41
    public function testId()
42
    {
43
        $response = new NotificationResponse($this->ok_payload);
44
45
        $this->assertEquals($this->ok_payload['id'], $response->getId());
46
    }
47
48
    public function testIdIsNull()
49
    {
50
        $raw = [];
51
        $response = new NotificationResponse($raw);
52
53
        $this->assertEquals(null, $response->getId());
54
    }
55
56
    public function testRecipientsCount()
57
    {
58
        $response = new NotificationResponse($this->ok_payload);
59
60
        $this->assertEquals($this->ok_payload['recipients'], $response->getRecipientsCount());
61
    }
62
63
    public function testRecipientsCount0()
64
    {
65
        $response = new NotificationResponse([]);
66
67
        $this->assertEquals(null, $response->getRecipientsCount());
68
    }
69
}
70