1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once 'base/PHPushbulletTestBase.php'; |
4
|
|
|
|
5
|
|
|
class DeviceTest extends PHPushbulletTestBase |
6
|
|
|
{ |
7
|
|
|
/** @test */ |
8
|
|
|
|
9
|
|
|
public function it_can_list_available_devices() |
10
|
|
|
{ |
11
|
|
|
$response = [ |
12
|
|
|
'devices' => [ |
13
|
|
|
$this->getDevice('android') |
14
|
|
|
] |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
$this->mock([ |
18
|
|
|
$this->okResponse($response) |
19
|
|
|
]); |
20
|
|
|
|
21
|
|
|
$response = $this->pushbullet->devices(); |
22
|
|
|
|
23
|
|
|
$this->assertInternalType('array', $response); |
24
|
|
|
$this->assertCount(1, $response); |
25
|
|
|
$this->assertInternalType('object', reset($response)); |
26
|
|
|
$this->assertInstanceOf('PHPushbullet\Device', reset($response)); |
27
|
|
|
|
28
|
|
|
$this->assertRequestHistory(['devices']); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @test */ |
32
|
|
|
|
33
|
|
|
public function it_can_chain_devices() |
34
|
|
|
{ |
35
|
|
|
$devices = [ |
36
|
|
|
'devices' => [ |
37
|
|
|
$this->getDevice('android'), |
38
|
|
|
$this->getDevice('chrome'), |
39
|
|
|
] |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
|
$response = $this->pushResponse([ |
45
|
|
|
'type' => 'note', |
46
|
|
|
'title' => 'Reminder', |
47
|
|
|
'body' => 'Do this thing', |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
$this->mock([ |
51
|
|
|
$this->okResponse($devices), |
52
|
|
|
$this->okResponse($response), |
53
|
|
|
$this->okResponse($response), |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$response = $this->pushbullet->device('Galaxy S4')->device('Chrome')->note('Title', 'Body'); |
57
|
|
|
|
58
|
|
|
$this->assertInternalType('array', $response); |
59
|
|
|
$this->assertCount(2, $response); |
60
|
|
|
|
61
|
|
|
$this->assertRequestHistory(['devices', 'pushes', 'pushes']); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** @test */ |
65
|
|
|
|
66
|
|
|
public function it_can_pass_multiple_devices() |
67
|
|
|
{ |
68
|
|
|
$devices = [ |
69
|
|
|
'devices' => [ |
70
|
|
|
$this->getDevice('android'), |
71
|
|
|
$this->getDevice('chrome'), |
72
|
|
|
] |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
$response = $this->pushResponse([ |
78
|
|
|
'type' => 'note', |
79
|
|
|
'title' => 'Reminder', |
80
|
|
|
'body' => 'Do this thing', |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$this->mock([ |
84
|
|
|
$this->okResponse($devices), |
85
|
|
|
$this->okResponse($response), |
86
|
|
|
$this->okResponse($response), |
87
|
|
|
]); |
88
|
|
|
|
89
|
|
|
$response = $this->pushbullet->device('Galaxy S4', 'Chrome')->note('Title', 'Body'); |
90
|
|
|
|
91
|
|
|
$this->assertInternalType('array', $response); |
92
|
|
|
$this->assertCount(2, $response); |
93
|
|
|
|
94
|
|
|
$this->assertRequestHistory(['devices', 'pushes', 'pushes']); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @test |
99
|
|
|
* @expectedException Exception |
100
|
|
|
* @expectedExceptionMessage You must specify something to push to. |
101
|
|
|
*/ |
102
|
|
|
|
103
|
|
|
public function it_throws_an_error_for_if_a_device_is_not_set() |
104
|
|
|
{ |
105
|
|
|
$this->pushbullet->note('Title', 'Body'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
* @expectedException Exception |
111
|
|
|
* @expectedExceptionMessage Chromebook is not a valid device. |
112
|
|
|
*/ |
113
|
|
|
|
114
|
|
|
public function it_throws_an_error_for_an_invalid_device() |
115
|
|
|
{ |
116
|
|
|
$response = [ |
117
|
|
|
'devices' => [ |
118
|
|
|
$this->getDevice('android') |
119
|
|
|
] |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$this->mock([ |
123
|
|
|
$this->okResponse($response) |
124
|
|
|
]); |
125
|
|
|
|
126
|
|
|
$this->pushbullet->device('Chromebook')->note('Title', 'Body'); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|