Skip to content

Commit bb0f5a0

Browse files
authored
Merge pull request #144 from ker0x/feature/travis-exception-deprecation
Add PHP 7.4 to Travis, improve lisibility of exception, add deprecation
2 parents 56d8218 + 2a37375 commit bb0f5a0

File tree

10 files changed

+47
-37
lines changed

10 files changed

+47
-37
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ php:
1010
- 7.1
1111
- 7.2
1212
- 7.3
13+
- 7.4
1314

1415
env:
1516
global:

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ The Messenger library follows [SemVer](http://semver.org/).
77
**Changelog** (since [`3.3.0`](https://github.com/ker0x/messenger/compare/3.3.0...3.3.1))
88

99
- 3.3.1 (2020-01)
10-
- Add Support of `CONFIRMED_EVENT_UPDATE` and `POST_PURCHASE_UPDATE` message tags.
11-
- Deprecated old message tags which will be disabled on March 4th, 2020 (see: [Current Supported Tags](https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags#current_supported_tags))
10+
- Add PHP 7.4 to Travis
11+
- Add Support of `CONFIRMED_EVENT_UPDATE` and `POST_PURCHASE_UPDATE` message tags. (Thanks to @BFoucher)
12+
- Deprecated old message tags which will be disabled on March 4th, 2020 (see [Current Supported Tags](https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags#current_supported_tags))
13+
- Buttons type `element_share` and `nested` are now deprecated
1214

1315
**Changelog** (since [`3.2.0`](https://github.com/ker0x/messenger/compare/3.2.0...3.3.0))
1416

src/Api/Send.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function isValidMessagingType(string $messagingType): void
8989
{
9090
$allowedMessagingType = $this->getAllowedMessagingType();
9191
if (!\in_array($messagingType, $allowedMessagingType, true)) {
92-
throw new InvalidTypeException(sprintf('messagingType must be either "%s".', implode(', ', $allowedMessagingType)));
92+
throw new InvalidTypeException(sprintf('"messagingType" must be either "%s".', implode(', ', $allowedMessagingType)));
9393
}
9494
}
9595

src/Helper/ValidatorTrait.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function isValidUrl(string $value): void
5454
'/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)$/',
5555
$value
5656
)) {
57-
throw new InvalidUrlException(sprintf('%s is not a valid url.', $value));
57+
throw new InvalidUrlException(sprintf('"%s" is not a valid url.', $value));
5858
}
5959
}
6060

@@ -64,7 +64,7 @@ protected function isValidUrl(string $value): void
6464
protected function isValidLocale(string $value): void
6565
{
6666
if (!preg_match('/^[a-z]{2}_[A-Z]{2}$/', $value)) {
67-
throw new InvalidLocaleException(sprintf('%s is not valid. Locale must be in ISO-639-1 and ISO-3166-1 format like fr_FR.', $value));
67+
throw new InvalidLocaleException(sprintf('"%s" is not valid. Locale must be in ISO-639-1 and ISO-3166-1 format like fr_FR.', $value));
6868
}
6969
}
7070

@@ -74,7 +74,7 @@ protected function isValidLocale(string $value): void
7474
protected function isValidCountry(string $value): void
7575
{
7676
if (!preg_match('/^[A-Z]{2}$/', $value)) {
77-
throw new InvalidCountryException(sprintf('%s is not valid. Country must be in ISO 3166 Alpha-2 format like FR.', $value));
77+
throw new InvalidCountryException(sprintf('"%s" is not valid. Country must be in ISO 3166 Alpha-2 format like FR.', $value));
7878
}
7979
}
8080

@@ -84,7 +84,7 @@ protected function isValidCountry(string $value): void
8484
protected function isValidDateTime(string $value): void
8585
{
8686
if (!preg_match('/^(\d{4})-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])T(0\d|1\d|2[0-3]):([0-5]\d)$/', $value)) {
87-
throw new InvalidDateTimeException(sprintf('%s is not valid. DateTime must be in ISO-8601 AAAA-MM-JJThh:mm format.', $value));
87+
throw new InvalidDateTimeException(sprintf('"%s" is not valid. DateTime must be in ISO-8601 AAAA-MM-JJThh:mm format.', $value));
8888
}
8989
}
9090

@@ -113,7 +113,7 @@ protected function isValidCurrency(string $value): void
113113

114114
$regex = '/^' . implode('|', $allowedCurrency) . '$/';
115115
if (!preg_match($regex, $value)) {
116-
throw new InvalidCurrencyException(sprintf('%s is not a valid currency. Currency must be in ISO-4217-3 format.', $value));
116+
throw new InvalidCurrencyException(sprintf('"%s" is not a valid currency. Currency must be in ISO-4217-3 format.', $value));
117117
}
118118
}
119119

@@ -124,7 +124,7 @@ protected function isValidExtension(string $filename, array $allowedExtension):
124124
{
125125
$ext = pathinfo($filename, PATHINFO_EXTENSION);
126126
if (empty($ext) || !\in_array($ext, $allowedExtension, true)) {
127-
throw new InvalidExtensionException(sprintf('%s does not have a valid extension. Allowed extensions are "%s".', $filename, implode(', ', $allowedExtension)));
127+
throw new InvalidExtensionException(sprintf('"%s" does not have a valid extension. Allowed extensions are "%s".', $filename, implode(', ', $allowedExtension)));
128128
}
129129
}
130130

@@ -138,11 +138,11 @@ protected function isValidButtons(array $buttons, array $allowedButtonsType): vo
138138
/** @var \Kerox\Messenger\Model\Common\Button\AbstractButton $button */
139139
foreach ($buttons as $button) {
140140
if (!$button instanceof AbstractButton) {
141-
throw new InvalidClassException(sprintf('Array can only contain instance of %s.', AbstractButton::class));
141+
throw new InvalidClassException(sprintf('Array can only contain instance of "%s".', AbstractButton::class));
142142
}
143143

144144
if (!\in_array($button->getType(), $allowedButtonsType, true)) {
145-
throw new InvalidClassException(sprintf('Buttons can only be an instance of %s.', implode(', ', $allowedButtonsType)));
145+
throw new InvalidClassException(sprintf('Buttons can only be an instance of "%s".', implode(', ', $allowedButtonsType)));
146146
}
147147
}
148148
}
@@ -162,7 +162,7 @@ protected function isValidMessage($message): Message
162162
return Message::create($message);
163163
}
164164

165-
throw new MessengerException(sprintf('message must be a string or an instance of %s or %s.', Message::class, Attachment::class));
165+
throw new MessengerException(sprintf('"message" must be a string or an instance of "%s" or "%s".', Message::class, Attachment::class));
166166
}
167167

168168
/**
@@ -172,7 +172,7 @@ protected function isValidSenderAction(string $action): void
172172
{
173173
$allowedSenderAction = $this->getAllowedSenderAction();
174174
if (!\in_array($action, $allowedSenderAction, true)) {
175-
throw new InvalidKeyException(sprintf('action must be either "%s".', implode(', ', $allowedSenderAction)));
175+
throw new InvalidKeyException(sprintf('"action" must be either "%s".', implode(', ', $allowedSenderAction)));
176176
}
177177
}
178178

@@ -183,7 +183,7 @@ protected function isValidNotificationType(string $notificationType): void
183183
{
184184
$allowedNotificationType = $this->getAllowedNotificationType();
185185
if (!\in_array($notificationType, $allowedNotificationType, true)) {
186-
throw new InvalidTypeException(sprintf('notificationType must be either "%s".', implode(', ', $allowedNotificationType)));
186+
throw new InvalidTypeException(sprintf('"notificationType" must be either "%s".', implode(', ', $allowedNotificationType)));
187187
}
188188
}
189189

@@ -198,20 +198,23 @@ protected function isValidTag(string $tag, $message = null): void
198198
$allowedTag = $this->getAllowedTag();
199199
$deprecatedTag = $this->getDeprecatedTags();
200200
if (!\in_array($tag, $allowedTag, true)) {
201-
throw new InvalidKeyException(sprintf('tag must be either "%s".', implode(', ', $allowedTag)));
201+
throw new InvalidKeyException(sprintf('"tag" must be either "%s".', implode(', ', $allowedTag)));
202202
}
203203

204204
if (\in_array($tag, $deprecatedTag, true)) {
205-
$message = sprintf('The %s tag is deprecated, use %s, %s, %s instead.',
205+
$message = sprintf('Tag "%s" is deprecated, use one of "%s" instead.',
206206
$tag,
207-
SendInterface::TAG_CONFIRMED_EVENT_UPDATE,
208-
SendInterface::TAG_POST_PURCHASE_UPDATE,
209-
SendInterface::TAG_ACCOUNT_UPDATE);
207+
implode(',', [
208+
SendInterface::TAG_CONFIRMED_EVENT_UPDATE,
209+
SendInterface::TAG_POST_PURCHASE_UPDATE,
210+
SendInterface::TAG_ACCOUNT_UPDATE,
211+
])
212+
);
210213
@trigger_error($message, E_USER_DEPRECATED);
211214
}
212215

213216
if ($tag === SendInterface::TAG_ISSUE_RESOLUTION && $message !== null && !$message instanceof GenericTemplate) {
214-
throw new InvalidClassException(sprintf('message must be an instance of %s if tag is set to %s.', GenericTemplate::class, SendInterface::TAG_ISSUE_RESOLUTION));
217+
throw new InvalidClassException(sprintf('"message" must be an instance of "%s" if tag is set to "%s".', GenericTemplate::class, SendInterface::TAG_ISSUE_RESOLUTION));
215218
}
216219
}
217220

src/Model/Common/Button/AbstractButton.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ abstract class AbstractButton implements \JsonSerializable
1313
public const TYPE_POSTBACK = 'postback';
1414
public const TYPE_PHONE_NUMBER = 'phone_number';
1515
public const TYPE_WEB_URL = 'web_url';
16-
public const TYPE_SHARE = 'element_share';
1716
public const TYPE_PAYMENT = 'payment';
1817
public const TYPE_ACCOUNT_LINK = 'account_link';
1918
public const TYPE_ACCOUNT_UNLINK = 'account_unlink';
19+
20+
/** @deprecated Since version 3.3.1 and will be removed in version 4.0.0. */
21+
public const TYPE_SHARE = 'element_share';
22+
23+
/** @deprecated Since version 3.3.1 and will be removed in version 4.0.0. */
2024
public const TYPE_NESTED = 'nested';
2125

2226
/**

tests/TestCase/Api/SendTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testSendAttachmentToUser(): void
8989
public function testBadMessage(): void
9090
{
9191
$this->expectException(MessengerException::class);
92-
$this->expectExceptionMessage('message must be a string or an instance of Kerox\Messenger\Model\Message or Kerox\Messenger\Model\Message\Attachment.');
92+
$this->expectExceptionMessage('"message" must be a string or an instance of "Kerox\Messenger\Model\Message" or "Kerox\Messenger\Model\Message\Attachment".');
9393
$this->sendApi->message('1008372609250235', 1234);
9494
}
9595

@@ -113,14 +113,14 @@ public function testSendMessageWithBadOptionsKey(): void
113113
public function testBadActionType(): void
114114
{
115115
$this->expectException(MessengerException::class);
116-
$this->expectExceptionMessage('action must be either "typing_on, typing_off, mark_seen".');
116+
$this->expectExceptionMessage('"action" must be either "typing_on, typing_off, mark_seen".');
117117
$this->sendApi->action('1008372609250235', 'typing_seen');
118118
}
119119

120120
public function testBadMessagingType(): void
121121
{
122122
$this->expectException(MessengerException::class);
123-
$this->expectExceptionMessage('messagingType must be either "RESPONSE, MESSAGE_TAG, NON_PROMOTIONAL_SUBSCRIPTION, UPDATE".');
123+
$this->expectExceptionMessage('"messagingType" must be either "RESPONSE, MESSAGE_TAG, NON_PROMOTIONAL_SUBSCRIPTION, UPDATE".');
124124
$this->sendApi->message('1008372609250235', 'Hello World!', [
125125
'messaging_type' => 'PROMOTIONAL_SUBSCRIPTION',
126126
]);
@@ -129,7 +129,7 @@ public function testBadMessagingType(): void
129129
public function testBadNotificationType(): void
130130
{
131131
$this->expectException(MessengerException::class);
132-
$this->expectExceptionMessage('notificationType must be either "REGULAR, SILENT_PUSH, NO_PUSH".');
132+
$this->expectExceptionMessage('"notificationType" must be either "REGULAR, SILENT_PUSH, NO_PUSH".');
133133
$this->sendApi->message('1008372609250235', 'Hello World!', [
134134
'notification_type' => 'UPDATE',
135135
]);
@@ -138,7 +138,7 @@ public function testBadNotificationType(): void
138138
public function testBadTagType(): void
139139
{
140140
$this->expectException(MessengerException::class);
141-
$this->expectExceptionMessage('tag must be either "CONFIRMED_EVENT_UPDATE, POST_PURCHASE_UPDATE, ACCOUNT_UPDATE, BUSINESS_PRODUCTIVITY, COMMUNITY_ALERT, CONFIRMED_EVENT_REMINDER, NON_PROMOTIONAL_SUBSCRIPTION, PAIRING_UPDATE, APPLICATION_UPDATE, PAYMENT_UPDATE, PERSONAL_FINANCE_UPDATE, SHIPPING_UPDATE, RESERVATION_UPDATE, ISSUE_RESOLUTION, APPOINTMENT_UPDATE, GAME_EVENT, TRANSPORTATION_UPDATE, FEATURE_FUNCTIONALITY_UPDATE, TICKET_UPDATE".');
141+
$this->expectExceptionMessage('"tag" must be either "CONFIRMED_EVENT_UPDATE, POST_PURCHASE_UPDATE, ACCOUNT_UPDATE, BUSINESS_PRODUCTIVITY, COMMUNITY_ALERT, CONFIRMED_EVENT_REMINDER, NON_PROMOTIONAL_SUBSCRIPTION, PAIRING_UPDATE, APPLICATION_UPDATE, PAYMENT_UPDATE, PERSONAL_FINANCE_UPDATE, SHIPPING_UPDATE, RESERVATION_UPDATE, ISSUE_RESOLUTION, APPOINTMENT_UPDATE, GAME_EVENT, TRANSPORTATION_UPDATE, FEATURE_FUNCTIONALITY_UPDATE, TICKET_UPDATE".');
142142
$this->sendApi->message('1008372609250235', 'Hello World!', [
143143
'notification_type' => SendInterface::NOTIFICATION_TYPE_REGULAR,
144144
'tag' => 'INVOICE_UPDATE',
@@ -150,7 +150,7 @@ public function testBadMessageForTagIssueResolution(): void
150150
$message = $this->getReceipt();
151151

152152
$this->expectException(MessengerException::class);
153-
$this->expectExceptionMessage('message must be an instance of Kerox\Messenger\Model\Message\Attachment\Template\GenericTemplate if tag is set to ISSUE_RESOLUTION.');
153+
$this->expectExceptionMessage('"message" must be an instance of "Kerox\Messenger\Model\Message\Attachment\Template\GenericTemplate" if tag is set to "ISSUE_RESOLUTION".');
154154
$this->sendApi->message('1008372609250235', $message, [
155155
'notification_type' => SendInterface::NOTIFICATION_TYPE_REGULAR,
156156
'tag' => SendInterface::TAG_ISSUE_RESOLUTION,

tests/TestCase/Helper/ValidatorTraitTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ public function testInvalidString(): void
2828
public function testInvalidUrl(): void
2929
{
3030
$this->expectException(MessengerException::class);
31-
$this->expectExceptionMessage('./img/image.png is not a valid url.');
31+
$this->expectExceptionMessage('"./img/image.png" is not a valid url.');
3232
$this->isValidUrl('./img/image.png');
3333
}
3434

3535
public function testInvalidLocale(): void
3636
{
3737
$this->expectException(MessengerException::class);
38-
$this->expectExceptionMessage('FR_fr is not valid. Locale must be in ISO-639-1 and ISO-3166-1 format like fr_FR.');
38+
$this->expectExceptionMessage('"FR_fr" is not valid. Locale must be in ISO-639-1 and ISO-3166-1 format like fr_FR.');
3939
$this->isValidLocale('FR_fr');
4040
}
4141

4242
public function testInvalidCountry(): void
4343
{
4444
$this->expectException(MessengerException::class);
45-
$this->expectExceptionMessage('us is not valid. Country must be in ISO 3166 Alpha-2 format like FR.');
45+
$this->expectExceptionMessage('"us" is not valid. Country must be in ISO 3166 Alpha-2 format like FR.');
4646
$this->isValidCountry('us');
4747
}
4848

4949
public function testInvalidDateTime(): void
5050
{
5151
$this->expectException(MessengerException::class);
52-
$this->expectExceptionMessage('20-11-2016T15:00 is not valid. DateTime must be in ISO-8601 AAAA-MM-JJThh:mm format.');
52+
$this->expectExceptionMessage('"20-11-2016T15:00" is not valid. DateTime must be in ISO-8601 AAAA-MM-JJThh:mm format.');
5353
$this->isValidDateTime('20-11-2016T15:00');
5454
}
5555

@@ -70,14 +70,14 @@ public function testInvalidArrayForMin(): void
7070
public function testInvalidCurrency(): void
7171
{
7272
$this->expectException(MessengerException::class);
73-
$this->expectExceptionMessage(' is not a valid currency. Currency must be in ISO-4217-3 format.');
73+
$this->expectExceptionMessage('"€" is not a valid currency. Currency must be in ISO-4217-3 format.');
7474
$this->isValidCurrency('');
7575
}
7676

7777
public function testInvalidExtension(): void
7878
{
7979
$this->expectException(MessengerException::class);
80-
$this->expectExceptionMessage('http://example.com/img/image.bmp does not have a valid extension. Allowed extensions are "jpg, png, gif".');
80+
$this->expectExceptionMessage('"http://example.com/img/image.bmp" does not have a valid extension. Allowed extensions are "jpg, png, gif".');
8181
$this->isValidExtension('http://example.com/img/image.bmp', ['jpg', 'png', 'gif']);
8282
}
8383
}

tests/TestCase/Model/Message/Attachment/Template/Element/MediaElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MediaElementTest extends AbstractTestCase
1414
public function testInvalidButton(): void
1515
{
1616
$this->expectException(MessengerException::class);
17-
$this->expectExceptionMessage('Buttons can only be an instance of web_url.');
17+
$this->expectExceptionMessage('Buttons can only be an instance of "web_url".');
1818

1919
$element = MediaElement::create('https://www.facebook.com/photo.php?fbid=1234567890')
2020
->setButtons([

tests/TestCase/Model/Message/Attachment/Template/Element/OpenGraphElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OpenGraphElementTest extends AbstractTestCase
1414
public function testInvalidButton(): void
1515
{
1616
$this->expectException(MessengerException::class);
17-
$this->expectExceptionMessage('Buttons can only be an instance of web_url');
17+
$this->expectExceptionMessage('Buttons can only be an instance of "web_url"');
1818

1919
$element = OpenGraphElement::create('https://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb')
2020
->setButtons([

tests/TestCase/Model/ProfileSettings/PersistentMenuTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PersistentMenuTest extends AbstractTestCase
1717
public function testInvalidButton(): void
1818
{
1919
$this->expectException(MessengerException::class);
20-
$this->expectExceptionMessage('Array can only contain instance of Kerox\Messenger\Model\Common\Button\AbstractButton.');
20+
$this->expectExceptionMessage('Array can only contain instance of "Kerox\Messenger\Model\Common\Button\AbstractButton".');
2121

2222
$persistentMenu = PersistentMenu::create()->setComposerInputDisabled(true)->addButtons([
2323
'Phone Number' => [
@@ -29,7 +29,7 @@ public function testInvalidButton(): void
2929
public function testInvalidButtonType(): void
3030
{
3131
$this->expectException(MessengerException::class);
32-
$this->expectExceptionMessage('Buttons can only be an instance of web_url, postback, nested.');
32+
$this->expectExceptionMessage('Buttons can only be an instance of "web_url, postback, nested".');
3333

3434
$persistentMenu = PersistentMenu::create()->setComposerInputDisabled(true)->addButtons([
3535
PhoneNumber::create('Phone number', 'PHONE_NUMBER_PAYLOAD'),

0 commit comments

Comments
 (0)