├── .gitignore
├── .travis.yml
├── README.md
├── composer.json
├── examples
├── basic-example.php
└── complete-example.php
├── phpunit.xml.dist
├── src
└── LeonardoTeixeira
│ └── Pushover
│ ├── Client.php
│ ├── Exceptions
│ ├── InvalidArgumentException.php
│ └── PushoverException.php
│ ├── Message.php
│ ├── Priority.php
│ ├── Receipt.php
│ ├── Sound.php
│ └── Status.php
└── tests
├── LeonardoTeixeira
└── Pushover
│ ├── ClientTest.php
│ ├── MessageTest.php
│ ├── PriorityTest.php
│ └── SountTest.php
└── bootstrap.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .buildpath
2 | .DS_Store
3 | .project
4 | .settings
5 | composer.lock
6 | composer.phar
7 | vendor/
8 |
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - '5.4'
5 | - '5.5'
6 | - '5.6'
7 | - '7.0'
8 | - '7.1'
9 | - hhvm
10 | - nightly
11 |
12 | before_script:
13 | - composer self-update
14 | - composer install --no-interaction --prefer-source --dev
15 |
16 | script: vendor/bin/phpunit
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pushover for PHP
2 |
3 | [](https://travis-ci.org/LeonardoTeixeira/pushover)
4 | [](https://packagist.org/packages/leonardoteixeira/pushover)
5 | [](https://packagist.org/packages/leonardoteixeira/pushover)
6 | [](https://packagist.org/packages/leonardoteixeira/pushover)
7 |
8 | A simple PHP library for the [Pushover](https://pushover.net) service.
9 |
10 | This library was written using the [PSR-4](http://www.php-fig.org/psr/psr-4/) standards.
11 |
12 | ## Installation
13 |
14 | Use the [Composer](https://getcomposer.org/) to install.
15 |
16 | ### composer.json
17 |
18 | ```json
19 | {
20 | "require": {
21 | "leonardoteixeira/pushover": "1.*"
22 | }
23 | }
24 | ```
25 |
26 | ### Running the composer
27 |
28 | ```
29 | composer install
30 | ```
31 |
32 | ## Usage
33 |
34 | ### Basic Example
35 |
36 | ```php
37 | push($message);
51 | echo 'The message has been pushed!', PHP_EOL;
52 | } catch (PushoverException $e) {
53 | echo 'ERROR: ', $e->getMessage(), PHP_EOL;
54 | }
55 | ```
56 | You also can pass a title and the priority on constructor:
57 |
58 | ```php
59 | $message = new Message('Your message here.', 'Title here', Priority::HIGH);
60 | ```
61 | ### Complete Example
62 |
63 | ```php
64 | setMessage('Your messsage here.');
82 | $message->setTitle('Title here');
83 | $message->setUrl('http://www.example.com/');
84 | $message->setAttachment('pic.jpg');
85 | $message->setUrlTitle('Click me!');
86 | $message->setPriority(Priority::HIGH);
87 | $message->setSound(Sound::SIREN);
88 | $message->setHtml(true);
89 | $message->setDate(new \DateTime());
90 |
91 | try {
92 | $receipt = $client->push($message);
93 | echo 'The message has been pushed!', PHP_EOL;
94 | $status = $client->poll($receipt);
95 | } catch (PushoverException $e) {
96 | echo 'ERROR: ', $e->getMessage(), PHP_EOL;
97 | }
98 | ```
99 |
100 | ### Emergency Priority
101 | For the emergency priority you must provide the parameters `retry` and `expire`. The `callback` parameter is optional.
102 |
103 | [More information](https://pushover.net/api#priority)
104 |
105 | ```php
106 | $message->setPriority(Priority::EMERGENCY);
107 | $message->setRetry(60);
108 | $message->setExpire(10800);
109 | $message->setCallback('http://callback-url.com/');
110 | ```
111 |
112 | You can poll the notification status using `poll`.
113 |
114 | ## Running the tests
115 |
116 | ```
117 | vendor/bin/phpunit
118 | ```
119 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "leonardoteixeira/pushover",
3 | "description": "A simple PHP library for the Pushover service",
4 | "keywords": [
5 | "pushover",
6 | "push",
7 | "notification",
8 | "api",
9 | "mobile",
10 | "ios",
11 | "iphone",
12 | "ipad",
13 | "android",
14 | "tablet"
15 | ],
16 | "type": "library",
17 | "homepage": "https://github.com/LeonardoTeixeira/pushover",
18 | "license": "MIT",
19 | "authors": [
20 | {
21 | "name": "Leonardo Cesar Teixeira",
22 | "email": "leonardo.teixeira@msn.com"
23 | }
24 | ],
25 | "repositories": [
26 | {
27 | "type": "git",
28 | "url": "https://github.com/LeonardoTeixeira/pushover.git"
29 | }
30 | ],
31 | "require": {
32 | "php": ">=5.4.0",
33 | "rmccue/requests": ">=1.0"
34 | },
35 | "require-dev": {
36 | "phpunit/phpunit": "4.1.*"
37 | },
38 | "autoload": {
39 | "psr-4": {
40 | "LeonardoTeixeira\\Pushover\\": "src/LeonardoTeixeira/Pushover/"
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/examples/basic-example.php:
--------------------------------------------------------------------------------
1 | push($message);
18 | echo 'The message has been pushed!', PHP_EOL;
19 | } catch (PushoverException $e) {
20 | echo 'ERROR: ', $e->getMessage(), PHP_EOL;
21 | }
22 |
--------------------------------------------------------------------------------
/examples/complete-example.php:
--------------------------------------------------------------------------------
1 | setMessage('Your messsage here.');
17 | $message->setTitle('Title here');
18 | $message->setUrl('http://www.example.com/');
19 | $message->setUrlTitle('Click me!');
20 | $message->setPriority(Priority::HIGH);
21 | $message->setSound(Sound::SIREN);
22 | $message->setHtml(true);
23 | $message->setDate(new \DateTime());
24 |
25 | try {
26 | $client->push($message);
27 | echo 'The message has been pushed!', PHP_EOL;
28 | } catch (PushoverException $e) {
29 | echo 'ERROR: ', $e->getMessage(), PHP_EOL;
30 | }
31 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 | tests/
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/LeonardoTeixeira/Pushover/Client.php:
--------------------------------------------------------------------------------
1 | user = $user;
20 | $this->token = $token;
21 | }
22 |
23 | public function getUser()
24 | {
25 | return $this->user;
26 | }
27 |
28 | public function getToken()
29 | {
30 | return $this->token;
31 | }
32 |
33 | public function setUser($user)
34 | {
35 | $this->user = $user;
36 | }
37 |
38 | public function setToken($token)
39 | {
40 | $this->token = $token;
41 | }
42 |
43 | public function push(Message $message, $device = null)
44 | {
45 | if (! $message instanceof Message) {
46 | throw new PushoverException('The parameter \'$message\' must be a Message instance.');
47 | }
48 |
49 | if ($message->getMessage() == null) {
50 | throw new PushoverException('The message content was not set.');
51 | }
52 |
53 | if ($message->getPriority() == Priority::EMERGENCY) {
54 | if (!$message->hasRetry()) {
55 | throw new PushoverException('The emergency priority must have the \'retry\' parameter.');
56 | }
57 |
58 | if (!$message->hasExpire()) {
59 | throw new PushoverException('The emergency priority must have the \'expire\' parameter.');
60 | }
61 | }
62 |
63 | $postData = [
64 | 'user' => $this->user,
65 | 'token' => $this->token,
66 | 'message' => $message->getMessage(),
67 | 'priority' => $message->getPriority()
68 | ];
69 |
70 | if ($device != null) {
71 | $postData['device'] = $device;
72 | }
73 |
74 | if ($message->hasTitle()) {
75 | $postData['title'] = $message->getTitle();
76 | }
77 |
78 | if ($message->hasUrl()) {
79 | $postData['url'] = $message->getUrl();
80 | }
81 |
82 | if ($message->hasUrlTitle()) {
83 | $postData['url_title'] = $message->getUrlTitle();
84 | }
85 |
86 | if ($message->getPriority() == Priority::EMERGENCY) {
87 | if ($message->hasRetry()) {
88 | $postData['retry'] = $message->getRetry();
89 | }
90 |
91 | if ($message->hasExpire()) {
92 | $postData['expire'] = $message->getExpire();
93 | }
94 |
95 | if ($message->hasCallback()) {
96 | $postData['callback'] = $message->getCallback();
97 | }
98 | }
99 |
100 | if ($message->hasSound()) {
101 | $postData['sound'] = $message->getSound();
102 | }
103 |
104 | if ($message->hasHtml()) {
105 | $postData['html'] = $message->getHtml();
106 | }
107 |
108 | if ($message->hasDate()) {
109 | $postData['timestamp'] = $message->getDate()->getTimestamp();
110 | }
111 |
112 | if ($message->hasAttachment()) {
113 | $postData['attachment'] = new \CURLFile(realpath($message->getAttachment()));
114 | }
115 |
116 | try {
117 | // Using hooks is an ugly hack since we bypass the fancy request API
118 | // Up to no, Requests doesn't support multi-part headers :-/
119 | //
120 | // Should we switch to guzzle/guzzle ?
121 | $hooks = new Requests_Hooks();
122 | $hooks->register('curl.before_send', function($fp) use ($postData) {
123 | curl_setopt($fp, CURLOPT_POSTFIELDS, $postData);
124 | $postData = [];
125 | });
126 | $hooks = ['hooks' => $hooks];
127 |
128 | $request = Requests::post(self::API_MESSAGE_URL, [], $postData, $hooks);
129 | $responseJson = json_decode($request->body);
130 |
131 | if (!isset($responseJson->status) || $responseJson->status != 1) {
132 | if (isset($responseJson->errors)) {
133 | throw new PushoverException($responseJson->errors[0]);
134 | } else {
135 | throw new PushoverException('Unable to access the Pushover API.');
136 | }
137 | }
138 | if(isset($responseJson->receipt)) {
139 | return new Receipt($responseJson->receipt);
140 | }
141 | return new Receipt();
142 |
143 | } catch (\Exception $e) {
144 | throw new PushoverException($e->getMessage());
145 | }
146 | }
147 |
148 | public function poll(Receipt $receipt)
149 | {
150 | if (! $receipt instanceof Receipt ) {
151 | throw new PushoverException('The parameter \'$receipt\' must be a Receipt instance.');
152 | }
153 |
154 | if(is_null($receipt->getReceipt())) {
155 | throw new PushoverException('The receipt content was not set.');
156 | }
157 |
158 | try {
159 | $request = Requests::get(self::API_RECEIPTS_URL.'/'.$receipt->getReceipt().'.json?token='.$this->token, []);
160 | $responseJson = json_decode($request->body, true);
161 |
162 | if (!isset($responseJson['status']) || $responseJson['status'] != 1) {
163 | if (isset($responseJson['errors'])) {
164 | throw new PushoverException($responseJson['errors'][0]);
165 | } else {
166 | throw new PushoverException('Unable to access the Pushover API.');
167 | }
168 | }
169 | return new Status($responseJson);
170 |
171 | } catch (\Exception $e) {
172 | throw new PushoverException($e->getMessage());
173 | }
174 | }
175 | public function cancel(Receipt $receipt)
176 | {
177 | if (! $receipt instanceof Receipt ) {
178 | throw new PushoverException('The parameter \'$receipt\' must be a Receipt instance.');
179 | }
180 |
181 | if(is_null($receipt->getReceipt())) {
182 | throw new PushoverException('The receipt content was not set.');
183 | }
184 |
185 | try {
186 | $request = Requests::post(self::API_RECEIPTS_URL.'/'.$receipt->getReceipt().'/cancel.json', [], ['token' => $this->token]);
187 | $responseJson = json_decode($request->body, true);
188 |
189 | if (!isset($responseJson['status']) || $responseJson['status'] != 1) {
190 | if (isset($responseJson['errors'])) {
191 | throw new PushoverException($responseJson['errors'][0]);
192 | } else {
193 | throw new PushoverException('Unable to access the Pushover API.');
194 | }
195 | }
196 | } catch (\Exception $e) {
197 | throw new PushoverException($e->getMessage());
198 | }
199 | }
200 | }
201 |
--------------------------------------------------------------------------------
/src/LeonardoTeixeira/Pushover/Exceptions/InvalidArgumentException.php:
--------------------------------------------------------------------------------
1 | message = $message;
25 | $this->title = $title;
26 | $this->priority = $priority;
27 | }
28 |
29 | public function getMessage()
30 | {
31 | return $this->message;
32 | }
33 |
34 | public function getTitle()
35 | {
36 | return $this->title;
37 | }
38 |
39 | public function getUrl()
40 | {
41 | return $this->url;
42 | }
43 |
44 | public function getUrlTitle()
45 | {
46 | return $this->urlTitle;
47 | }
48 |
49 | public function getPriority()
50 | {
51 | return $this->priority;
52 | }
53 |
54 | public function getRetry()
55 | {
56 | return $this->retry;
57 | }
58 |
59 | public function getExpire()
60 | {
61 | return $this->expire;
62 | }
63 |
64 | public function getCallback()
65 | {
66 | return $this->callback;
67 | }
68 |
69 | public function getSound()
70 | {
71 | return $this->sound;
72 | }
73 |
74 | public function getHtml()
75 | {
76 | return $this->html;
77 | }
78 |
79 | public function getDate()
80 | {
81 | return $this->date;
82 | }
83 |
84 | public function getAttachment()
85 | {
86 | return $this->attachment;
87 | }
88 |
89 | public function setMessage($message)
90 | {
91 | $this->message = $message;
92 | }
93 |
94 | public function setTitle($title)
95 | {
96 | $this->title = $title;
97 | }
98 |
99 | public function setUrl($url)
100 | {
101 | $this->url = $url;
102 | }
103 |
104 | public function setUrlTitle($urlTitle)
105 | {
106 | $this->urlTitle = $urlTitle;
107 | }
108 |
109 | public function setPriority($priority)
110 | {
111 | if (!Priority::has($priority)) {
112 | throw new InvalidArgumentException('The priority \'' . $priority . '\' is invalid.');
113 | }
114 | $this->priority = $priority;
115 | }
116 |
117 | public function setRetry($retry)
118 | {
119 | $this->retry = $retry;
120 | }
121 |
122 | public function setExpire($expire)
123 | {
124 | $this->expire = $expire;
125 | }
126 |
127 | public function setCallback($callback)
128 | {
129 | $this->callback = $callback;
130 | }
131 |
132 | public function setSound($sound)
133 | {
134 | if (!Sound::has($sound)) {
135 | throw new InvalidArgumentException('The sound \'' . $sound . '\' is invalid.');
136 | }
137 | $this->sound = $sound;
138 | }
139 |
140 | public function setHtml($html)
141 | {
142 | if ($html)
143 | $this->html = 1;
144 | else
145 | $this->html = 0;
146 | }
147 |
148 | public function setDate(\DateTime $date)
149 | {
150 | $this->date = $date;
151 | }
152 |
153 | public function setAttachment($attachment)
154 | {
155 | $this->attachment = $attachment;
156 | }
157 |
158 | public function hasTitle()
159 | {
160 | return !is_null($this->title);
161 | }
162 |
163 | public function hasUrl()
164 | {
165 | return !is_null($this->url);
166 | }
167 |
168 | public function hasUrlTitle()
169 | {
170 | return !is_null($this->urlTitle);
171 | }
172 |
173 | public function hasRetry()
174 | {
175 | return !is_null($this->retry);
176 | }
177 |
178 | public function hasExpire()
179 | {
180 | return !is_null($this->expire);
181 | }
182 |
183 | public function hasCallback()
184 | {
185 | return !is_null($this->callback);
186 | }
187 |
188 | public function hasSound()
189 | {
190 | return !is_null($this->sound);
191 | }
192 |
193 | public function hasHtml()
194 | {
195 | return !is_null($this->html);
196 | }
197 |
198 | public function hasDate()
199 | {
200 | return ($this->date instanceof \DateTime);
201 | }
202 |
203 | public function hasAttachment()
204 | {
205 | return file_exists($this->attachment);
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/src/LeonardoTeixeira/Pushover/Priority.php:
--------------------------------------------------------------------------------
1 | receipt = $receipt;
12 | }
13 |
14 | public function getReceipt()
15 | {
16 | return $this->receipt;
17 | }
18 |
19 | public function setReceipt($receipt)
20 | {
21 | $this->receipt = $receipt;
22 | }
23 |
24 | public function hasReceipt()
25 | {
26 | return !is_null($this->receipt);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/LeonardoTeixeira/Pushover/Sound.php:
--------------------------------------------------------------------------------
1 | null,
21 | self::ACKNOWLEDGED_AT => null,
22 | self::ACKNOWLEDGED_BY => null,
23 | self::ACKNOWLEDGED_BY_DEVICE => null,
24 | self::LAST_DELIVERED_AT => null,
25 | self::EXPIRED => null,
26 | self::EXPIRED_AT => null,
27 | self::CALLED_BACK => null,
28 | self::CALLED_BACK_AT => null
29 | ];
30 |
31 | public function __construct($status = null)
32 | {
33 | if(!is_null($status)) {
34 | if(!is_array($status))
35 | throw new InvalidArgumentException('The status \'' . $status . '\' is invalid.');
36 |
37 | foreach($status as $key => $value) {
38 | if(array_key_exists($key, $this->status)) {
39 | $this->status[$key] = $value;
40 | }
41 | }
42 | }
43 | }
44 |
45 | public function setAcknowledged($value)
46 | {
47 | $this->status[self::ACKNOWLEDGED] = $value;
48 | }
49 |
50 | public function setAcknowledgedAt($value)
51 | {
52 | $this->status[self::ACKNOWLEDGED_AT] = $value;
53 | }
54 |
55 | public function setAcknowledgedBy($value)
56 | {
57 | $this->status[self::ACKNOWLEDGED_BY] = $value;
58 | }
59 |
60 | public function setAcknowledgedByDevice($value)
61 | {
62 | $this->status[self::ACKNOWLEDGED_BY_DEVICE] = $value;
63 | }
64 |
65 | public function setLastDeliveredAt($value)
66 | {
67 | $this->status[self::LAST_DELIVERED_AT] = $value;
68 | }
69 |
70 | public function setExpired($value)
71 | {
72 | $this->status[self::EXPIRED] = $value;
73 | }
74 |
75 | public function setExpiredAt($value)
76 | {
77 | $this->status[self::EXPIRED_AT] = $value;
78 | }
79 |
80 | public function setCalledBack($value)
81 | {
82 | $this->status[self::CALLED_BACK] = $value;
83 | }
84 |
85 | public function setCalledBackAt($value)
86 | {
87 | $this->status[self::CALLED_BACK_AT] = $value;
88 | }
89 |
90 | public function getAcknowledged()
91 | {
92 | return $this->status[self::ACKNOWLEDGED];
93 | }
94 |
95 | public function getAcknowledgedAt()
96 | {
97 | return $this->status[self::ACKNOWLEDGED_AT];
98 | }
99 |
100 | public function getAcknowledgedBy()
101 | {
102 | return $this->status[self::ACKNOWLEDGED_BY];
103 | }
104 |
105 | public function getAcknowledgedByDevice()
106 | {
107 | return $this->status[self::ACKNOWLEDGED_BY_DEVICE];
108 | }
109 |
110 | public function getLastDeliveredAt()
111 | {
112 | return $this->status[self::LAST_DELIVERED_AT];
113 | }
114 |
115 | public function getExpired()
116 | {
117 | return $this->status[self::EXPIRED];
118 | }
119 |
120 | public function getExpiredAt()
121 | {
122 | return $this->status[self::EXPIRED_AT];
123 | }
124 |
125 | public function getCalledBack()
126 | {
127 | return $this->status[self::CALLED_BACK];
128 | }
129 |
130 | public function getCalledBackAt()
131 | {
132 | return $this->status[self::CALLED_BACK_AT];
133 | }
134 |
135 | public function hasAcknowledged()
136 | {
137 | return !is_null($this->status[self::ACKNOWLEDGED]);
138 | }
139 |
140 | public function hasAcknowledgedAt()
141 | {
142 | return !is_null($this->status[self::ACKNOWLEDGED_AT]);
143 | }
144 |
145 | public function hasAcknowledgedBy()
146 | {
147 | return !is_null($this->status[self::ACKNOWLEDGED_BY]);
148 | }
149 |
150 | public function hasAcknowledgedByDevice()
151 | {
152 | return !is_null($this->status[self::ACKNOWLEDGED_BY_DEVICE]);
153 | }
154 |
155 | public function hasLastDeliveredAt()
156 | {
157 | return !is_null($this->status[self::LAST_DELIVERED_AT]);
158 | }
159 |
160 | public function hasExpired()
161 | {
162 | return !is_null($this->status[self::EXPIRED]);
163 | }
164 |
165 | public function hasExpiredAt()
166 | {
167 | return !is_null($this->status[self::EXPIRED_AT]);
168 | }
169 |
170 | public function hasCalledBack()
171 | {
172 | return !is_null($this->status[self::CALLED_BACK]);
173 | }
174 |
175 | public function hasCalledBackAt()
176 | {
177 | return !is_null($this->status[self::CALLED_BACK_AT]);
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/tests/LeonardoTeixeira/Pushover/ClientTest.php:
--------------------------------------------------------------------------------
1 | clients = [
12 | [
13 | 'user' => 'DFx4rPNV232ad49uzPE4vAKaU2m67q',
14 | 'token' => 'khvGW7kDj4MeJ2uG8c3z973No49wWY'
15 | ],
16 | [
17 | 'user' => '2T72X267muFg2FGZqT46ze8KskxMmA',
18 | 'token' => '4GmnbfBcr3rR4VT7r2G4eK22HL7a2J'
19 | ],
20 | [
21 | 'user' => 'LB787zoD82899PqpT6zbiGeaAAo8xA',
22 | 'token' => 'Q7HTQ9yjW8LRfroy83V34764ydaYQE'
23 | ]
24 | ];
25 | }
26 |
27 | public function testConstructor()
28 | {
29 | foreach ($this->clients as $client) {
30 | $c = new Client($client['user'], $client['token']);
31 | $this->assertEquals($client['user'], $c->getUser());
32 | $this->assertEquals($client['token'], $c->getToken());
33 | }
34 | }
35 |
36 | public function testGettersAndSetters()
37 | {
38 | foreach ($this->clients as $client) {
39 | $c = new Client();
40 | $c->setUser($client['user']);
41 | $c->setToken($client['token']);
42 | $this->assertEquals($client['user'], $c->getUser());
43 | $this->assertEquals($client['token'], $c->getToken());
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/LeonardoTeixeira/Pushover/MessageTest.php:
--------------------------------------------------------------------------------
1 | messages = [
12 | [
13 | 'title' => 'Example Message 1',
14 | 'message' => 'Example content message 1.',
15 | 'url' => 'http://www.google.com/',
16 | 'url_title' => 'Google',
17 | 'priority' => - 2,
18 | 'sound' => 'classical',
19 | 'html' => 1,
20 | 'date' => '2014-08-14'
21 | ],
22 | [
23 | 'title' => 'Example Message 2',
24 | 'message' => 'Example content message 2.',
25 | 'url' => 'https://github.com/',
26 | 'url_title' => 'Github',
27 | 'priority' => 1,
28 | 'sound' => 'spacealarm',
29 | 'html' => 1,
30 | 'date' => '2014-08-10'
31 | ],
32 | [
33 | 'title' => 'Example Message 3',
34 | 'message' => 'Example content message 3.',
35 | 'url' => 'https://slack.com/',
36 | 'url_title' => 'Slack',
37 | 'priority' => 2,
38 | 'sound' => 'mechanical',
39 | 'html' => 1,
40 | 'date' => '2017-01-19',
41 | 'retry' => 30,
42 | 'expire' => 7200,
43 | 'callback' => 'http://localhost'
44 | ]
45 | ];
46 | }
47 |
48 | public function testConstructor()
49 | {
50 | foreach ($this->messages as $message) {
51 | $m = new Message($message['message'], $message['title'], $message['priority']);
52 | $this->assertEquals($message['title'], $m->getTitle());
53 | $this->assertEquals($message['message'], $m->getMessage());
54 | $this->assertEquals($message['priority'], $m->getPriority());
55 | }
56 | }
57 |
58 | public function testGettersAndSetters()
59 | {
60 | foreach ($this->messages as $message) {
61 | $m = new Message();
62 |
63 | $m->setTitle($message['title']);
64 | $m->setMessage($message['message']);
65 | $m->setUrl($message['url']);
66 | $m->setUrlTitle($message['url_title']);
67 | $m->setPriority($message['priority']);
68 | $m->setSound($message['sound']);
69 | $m->setHtml($message['html']);
70 | $m->setDate(new \DateTime($message['date']));
71 | if ($message['priority'] == 2) {
72 | $m->setRetry($message['retry']);
73 | $m->setExpire($message['expire']);
74 | $m->setCallback($message['callback']);
75 | }
76 |
77 | $this->assertEquals($message['title'], $m->getTitle());
78 | $this->assertEquals($message['message'], $m->getMessage());
79 | $this->assertEquals($message['url'], $m->getUrl());
80 | $this->assertEquals($message['url_title'], $m->getUrlTitle());
81 | $this->assertEquals($message['priority'], $m->getPriority());
82 | $this->assertEquals($message['sound'], $m->getSound());
83 | $this->assertEquals($message['html'], $m->getHtml());
84 | $this->assertEquals($message['date'], $m->getDate()
85 | ->format('Y-m-d'));
86 | if ($message['priority'] == 2) {
87 | $this->assertEquals($message['retry'], $m->getRetry());
88 | $this->assertEquals($message['expire'], $m->getExpire());
89 | $this->assertEquals($message['callback'], $m->getCallback());
90 | }
91 | }
92 | }
93 |
94 | public function testHasMethods()
95 | {
96 | foreach ($this->messages as $message) {
97 | $m = new Message();
98 |
99 | $m->setMessage($message['message']);
100 | $m->setPriority($message['priority']);
101 |
102 | $this->assertFalse($m->hasTitle());
103 | $this->assertFalse($m->hasUrl());
104 | $this->assertFalse($m->hasUrlTitle());
105 | $this->assertFalse($m->hasRetry());
106 | $this->assertFalse($m->hasExpire());
107 | $this->assertFalse($m->hasCallback());
108 | $this->assertFalse($m->hasSound());
109 | $this->assertFalse($m->hasHtml());
110 | $this->assertFalse($m->hasDate());
111 | }
112 |
113 | foreach ($this->messages as $message) {
114 | $m = new Message();
115 |
116 | $m->setTitle($message['title']);
117 | $m->setMessage($message['message']);
118 | $m->setUrl($message['url']);
119 | $m->setUrlTitle($message['url_title']);
120 | $m->setPriority($message['priority']);
121 | $m->setSound($message['sound']);
122 | $m->setHtml($message['html']);
123 | $m->setDate(new \DateTime($message['date']));
124 | if ($message['priority'] == 2) {
125 | $m->setRetry($message['retry']);
126 | $m->setExpire($message['expire']);
127 | $m->setCallback($message['callback']);
128 | }
129 |
130 | $this->assertTrue($m->hasTitle());
131 | $this->assertTrue($m->hasUrl());
132 | $this->assertTrue($m->hasUrlTitle());
133 | $this->assertTrue($m->hasSound());
134 | $this->assertTrue($m->hasHtml());
135 | $this->assertTrue($m->hasDate());
136 |
137 | if ($message['priority'] == 2) {
138 | $this->assertTrue($m->hasRetry());
139 | $this->assertTrue($m->hasExpire());
140 | $this->assertTrue($m->hasCallback());
141 | } else {
142 | $this->assertFalse($m->hasRetry());
143 | $this->assertFalse($m->hasExpire());
144 | $this->assertFalse($m->hasCallback());
145 | }
146 | }
147 | }
148 |
149 | /**
150 | * @expectedException LeonardoTeixeira\Pushover\Exceptions\InvalidArgumentException
151 | */
152 | public function testInvalidArgumentExceptionFromPriority()
153 | {
154 | $m = new Message();
155 | $m->setPriority(-5);
156 | }
157 |
158 | /**
159 | * @expectedException LeonardoTeixeira\Pushover\Exceptions\InvalidArgumentException
160 | */
161 | public function testInvalidArgumentExceptionFromSound()
162 | {
163 | $m = new Message();
164 | $m->setSound('invalid_sound');
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/tests/LeonardoTeixeira/Pushover/PriorityTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(- 2, Priority::LOWEST);
10 | $this->assertEquals(- 1, Priority::LOW);
11 | $this->assertEquals(0, Priority::NORMAL);
12 | $this->assertEquals(1, Priority::HIGH);
13 | $this->assertEquals(2, Priority::EMERGENCY);
14 | }
15 |
16 | public function testIfPriorityExists()
17 | {
18 | $this->assertTrue(Priority::has(-2));
19 | $this->assertTrue(Priority::has(-1));
20 | $this->assertTrue(Priority::has(0));
21 | $this->assertTrue(Priority::has(1));
22 | $this->assertTrue(Priority::has(2));
23 | $this->assertFalse(Priority::has(-5));
24 | $this->assertFalse(Priority::has(10));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/LeonardoTeixeira/Pushover/SountTest.php:
--------------------------------------------------------------------------------
1 | sounds = [
13 | 'pushover',
14 | 'bike',
15 | 'bugle',
16 | 'cashregister',
17 | 'classical',
18 | 'cosmic',
19 | 'falling',
20 | 'gamelan',
21 | 'incoming',
22 | 'intermission',
23 | 'magic',
24 | 'mechanical',
25 | 'pianobar',
26 | 'siren',
27 | 'spacealarm',
28 | 'tugboat',
29 | 'alien',
30 | 'climb',
31 | 'persistent',
32 | 'echo',
33 | 'updown',
34 | 'none'
35 | ];
36 | }
37 |
38 | public function testContainsAllSounds()
39 | {
40 | $allSounds = Sound::getAllSounds();
41 | foreach ($this->sounds as $sound) {
42 | $this->assertContains($sound, $allSounds);
43 | }
44 | }
45 |
46 | public function testIfSoundExists()
47 | {
48 | $this->assertTrue(Sound::has('mechanical'));
49 | $this->assertFalse(Sound::has('invalid_sound'));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 |