diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 450cd22..95d40a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: ['7.0', '7.4', '8.0', '8.3'] + version: ['7.1', '7.4', '8.0', '8.4'] max-parallel: 2 steps: @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: ['7.0', '7.4', '8.0', '8.3'] + version: ['7.1', '7.4', '8.0', '8.4'] max-parallel: 1 steps: diff --git a/README.md b/README.md index 4ded891..06f9439 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A software development kit to provide ways to interact with CM.com's Text servic ### Requirements -- php 7.* or 8.0 or 8.1 or 8.2 or 8.3 +- php 7.1 through 8.4 (inclusive) ## Usage diff --git a/composer.json b/composer.json index 4012b91..bb13232 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "cmdotcom/text-sdk-php", "description": "PHP SDK to send messages with CM.com", "type": "library", - "version": "2.3.1", + "version": "3.0.0", "keywords": ["sms","cm.com","rcs","whatsapp","viber","line","wechat","imessage","twitter","instagram"], "homepage": "https://www.cm.com/products/text/", "license": "MIT", @@ -16,10 +16,10 @@ "require": { "ext-curl": "*", "ext-json": "*", - "php": "^7.0||^8.0" + "php": "^7.1||^8.0" }, "require-dev": { - "phpunit/phpunit": "~6.0||~9.0" + "phpunit/phpunit": "~7.0||~9.0" }, "autoload": { "psr-0": { diff --git a/src/CMText/ITextClient.php b/src/CMText/ITextClient.php index 6953509..7188837 100644 --- a/src/CMText/ITextClient.php +++ b/src/CMText/ITextClient.php @@ -22,7 +22,7 @@ public function __construct( * @param string $message - Message body to send * @param string $from - Sender name * @param array $to - Recipient phonenumbers - * @param string $reference optional + * @param string|null $reference optional * * @return TextClientResult */ @@ -30,7 +30,7 @@ public function SendMessage( string $message, string $from, array $to, - string $reference = null + ?string $reference = null ); /** diff --git a/src/CMText/Message.php b/src/CMText/Message.php index f17c420..04381e0 100644 --- a/src/CMText/Message.php +++ b/src/CMText/Message.php @@ -106,11 +106,16 @@ class Message implements JsonSerializable * * @param string|MessageBody $body * @param string|null $from - * @param array $to + * @param array|null $to * @param string|null $reference * @throws \CMText\Exceptions\RecipientLimitException */ - public function __construct($body = '', string $from = null, array $to = [], string $reference = null) + public function __construct( + $body = '', + ?string $from = null, + ?array $to = [], + ?string $reference = null + ) { $this->__set('body', $body); $this->__set('from', $from); diff --git a/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveContent.php b/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveContent.php index 9b9abae..ccfe98c 100644 --- a/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveContent.php +++ b/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveContent.php @@ -25,10 +25,10 @@ class WhatsAppInteractiveContent implements \JsonSerializable */ public function __construct( string $type, - WhatsAppInteractiveHeader $header = null, - WhatsAppInteractiveBody $body = null, - IWhatsAppInteractiveAction $action = null, - WhatsAppInteractiveFooter $footer = null + ?WhatsAppInteractiveHeader $header = null, + ?WhatsAppInteractiveBody $body = null, + ?IWhatsAppInteractiveAction $action = null, + ?WhatsAppInteractiveFooter $footer = null ) { if( !in_array( diff --git a/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveHeader.php b/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveHeader.php index 620b32f..7977349 100644 --- a/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveHeader.php +++ b/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveHeader.php @@ -14,14 +14,14 @@ class WhatsAppInteractiveHeader /** * @param string $type - * @param string $text + * @param string|null $text * @param MediaContent|null $media * @throws \Exception */ public function __construct( string $type, - string $text = null, - MediaContent $media = null) + ?string $text = null, + ?MediaContent $media = null) { if( !in_array($type, (new \ReflectionClass(WhatsAppInteractiveHeaderTypes::class))->getConstants()) ){ throw new \Exception("Unsupported WhatsApp-InteractiveHeader-type $type"); diff --git a/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveSectionRow.php b/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveSectionRow.php index 8118db6..c06da1f 100644 --- a/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveSectionRow.php +++ b/src/CMText/RichContent/Messages/WhatsApp/WhatsAppInteractiveSectionRow.php @@ -19,7 +19,7 @@ class WhatsAppInteractiveSectionRow public function __construct( string $title, string $id, - string $description = null + ?string $description = null ) { $this->title = $title; diff --git a/src/CMText/RichContent/Suggestions/ReplySuggestion.php b/src/CMText/RichContent/Suggestions/ReplySuggestion.php index c489b1a..69f98b6 100644 --- a/src/CMText/RichContent/Suggestions/ReplySuggestion.php +++ b/src/CMText/RichContent/Suggestions/ReplySuggestion.php @@ -22,7 +22,7 @@ class ReplySuggestion extends SuggestionBase public function __construct( string $Label, - string $Text = null + ?string $Text = null ) { $this->label = $Label; diff --git a/src/CMText/TextClient.php b/src/CMText/TextClient.php index ffdc765..254803f 100644 --- a/src/CMText/TextClient.php +++ b/src/CMText/TextClient.php @@ -32,7 +32,7 @@ class TextClient implements ITextClient /** * SDK Version constant */ - const VERSION = '2.3.1'; + const VERSION = '3.0.0'; /** @@ -70,7 +70,7 @@ public function SendMessage( string $message, string $from, array $to, - string $reference = null + ?string $reference = null ) { // send it out instantly diff --git a/src/CMText/TextClientResult.php b/src/CMText/TextClientResult.php index 0ee804b..9c7d112 100644 --- a/src/CMText/TextClientResult.php +++ b/src/CMText/TextClientResult.php @@ -26,9 +26,9 @@ class TextClientResult * TextClientResult constructor. * * @param int $httpStatusCode - * @param string $responseBody + * @param string|null $responseBody */ - public function __construct(int $httpStatusCode, $responseBody = '') + public function __construct(int $httpStatusCode, ?string $responseBody = '') { $this->httpStatusCode = $httpStatusCode; $this->response = $responseBody; diff --git a/tests/CMText/RichContent/Common/ContactTest.php b/tests/CMText/RichContent/Common/ContactTest.php index e9b515f..2bb7525 100644 --- a/tests/CMText/RichContent/Common/ContactTest.php +++ b/tests/CMText/RichContent/Common/ContactTest.php @@ -30,31 +30,37 @@ public function testJsonSerialize() public function testAddUrl() { - $this->assertObjectHasAttribute( - 'urls', - (new Contact( - $this->contactProperties['url'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['url'] + ))->jsonSerialize(), + 'urls' + ) ); } public function testAddPhonenumber() { - $this->assertObjectHasAttribute( - 'phones', - (new Contact( - $this->contactProperties['phonenumber'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['phonenumber'] + ))->jsonSerialize(), + 'phones' + ) ); } public function testSetOrganization() { - $this->assertObjectHasAttribute( - 'org', - (new Contact( - $this->contactProperties['organization'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['organization'] + ))->jsonSerialize(), + 'org' + ) ); } @@ -95,41 +101,49 @@ public function test__construct() public function testSetBirthday() { - $this->assertObjectHasAttribute( - 'birthday', - (new Contact( - $this->contactProperties['birthday'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['birthday'] + ))->jsonSerialize(), + 'birthday' + ) ); } public function testSetName() { - $this->assertObjectHasAttribute( - 'name', - (new Contact( - $this->contactProperties['name'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['name'] + ))->jsonSerialize(), + 'name' + ) ); } public function testAddEmail() { - $this->assertObjectHasAttribute( - 'emails', - (new Contact( - $this->contactProperties['email'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['email'] + ))->jsonSerialize(), + 'emails' + ) ); } public function testAddAddress() { - $this->assertObjectHasAttribute( - 'addresses', - (new Contact( - $this->contactProperties['address'] - ))->jsonSerialize() + $this->assertTrue( + property_exists( + (new Contact( + $this->contactProperties['address'] + ))->jsonSerialize(), + 'addresses' + ) ); } diff --git a/tests/CMText/RichContent/Common/LineItemTest.php b/tests/CMText/RichContent/Common/LineItemTest.php index 761fb6e..ddf2e95 100644 --- a/tests/CMText/RichContent/Common/LineItemTest.php +++ b/tests/CMText/RichContent/Common/LineItemTest.php @@ -17,19 +17,16 @@ public function test__construct() $json = json_decode(json_encode($lineitem)); - $this->assertObjectHasAttribute( - 'label', - $json + $this->assertTrue( + property_exists($json, 'label') ); - $this->assertObjectHasAttribute( - 'type', - $json + $this->assertTrue( + property_exists($json, 'type') ); - $this->assertObjectHasAttribute( - 'amount', - $json + $this->assertTrue( + property_exists($json, 'amount') ); } } diff --git a/tests/CMText/RichContent/Messages/PaymentMessageTest.php b/tests/CMText/RichContent/Messages/PaymentMessageTest.php index 1c0d254..aee8a9d 100644 --- a/tests/CMText/RichContent/Messages/PaymentMessageTest.php +++ b/tests/CMText/RichContent/Messages/PaymentMessageTest.php @@ -34,9 +34,8 @@ public function test__construct() $json = json_decode(json_encode($message)); - $this->assertObjectHasAttribute( - 'payment', - $json + $this->assertTrue( + property_exists($json, 'payment') ); } } diff --git a/tests/CMText/RichContent/Payments/ApplePayConfigurationTest.php b/tests/CMText/RichContent/Payments/ApplePayConfigurationTest.php index 9e2e47d..9a606f1 100644 --- a/tests/CMText/RichContent/Payments/ApplePayConfigurationTest.php +++ b/tests/CMText/RichContent/Payments/ApplePayConfigurationTest.php @@ -31,59 +31,48 @@ public function test__construct() $json = json_decode(json_encode($configuration)); - $this->assertObjectHasAttribute( - 'merchantName', - $json + $this->assertTrue( + property_exists($json, 'merchantName') ); - $this->assertObjectHasAttribute( - 'description', - $json + $this->assertTrue( + property_exists($json, 'description') ); - $this->assertObjectHasAttribute( - 'orderReference', - $json + $this->assertTrue( + property_exists($json, 'orderReference') ); - $this->assertObjectHasAttribute( - 'total', - $json + $this->assertTrue( + property_exists($json, 'total') ); - $this->assertObjectHasAttribute( - 'currencyCode', - $json + $this->assertTrue( + property_exists($json, 'currencyCode') ); - $this->assertObjectHasAttribute( - 'recipientEmail', - $json + $this->assertTrue( + property_exists($json, 'recipientEmail') ); - $this->assertObjectHasAttribute( - 'recipientCountryCode', - $json + $this->assertTrue( + property_exists($json, 'recipientCountryCode') ); - $this->assertObjectHasAttribute( - 'languageCountryCode', - $json + $this->assertTrue( + property_exists($json, 'languageCountryCode') ); - $this->assertObjectHasAttribute( - 'billingAddressRequired', - $json + $this->assertTrue( + property_exists($json, 'billingAddressRequired') ); - $this->assertObjectHasAttribute( - 'shippingContactRequired', - $json + $this->assertTrue( + property_exists($json, 'shippingContactRequired') ); - $this->assertObjectHasAttribute( - 'lineItems', - $json + $this->assertTrue( + property_exists($json, 'lineItems') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentButtonTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentButtonTest.php index b58025d..639bb8a 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentButtonTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentButtonTest.php @@ -21,9 +21,8 @@ public function test__construct() $json->type ); - $this->assertObjectHasAttribute( - 'index', - $json + $this->assertTrue( + property_exists($json, 'index') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterCurrencyTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterCurrencyTest.php index cf68867..ae8ce7b 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterCurrencyTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterCurrencyTest.php @@ -21,19 +21,16 @@ public function testJsonSerialize() $json = json_decode( json_encode($currency) ); - $this->assertObjectHasAttribute( - 'currency', - $json + $this->assertTrue( + property_exists($json, 'currency') ); - $this->assertObjectHasAttribute( - 'code', - $json->currency + $this->assertTrue( + property_exists($json->currency, 'code') ); - $this->assertObjectHasAttribute( - 'amount_1000', - $json->currency + $this->assertTrue( + property_exists($json->currency, 'amount_1000') ); $this->assertEquals( @@ -41,9 +38,8 @@ public function testJsonSerialize() $json->currency->amount_1000 ); - $this->assertObjectHasAttribute( - 'fallback_value', - $json->currency + $this->assertTrue( + property_exists($json->currency, 'fallback_value') ); } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDatetimeTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDatetimeTest.php index 29b2ff6..1bedd53 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDatetimeTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDatetimeTest.php @@ -35,19 +35,16 @@ public function testJsonSerialize() $json = json_decode(json_encode($componentParameter)); - $this->assertObjectHasAttribute( - 'date_time', - $json + $this->assertTrue( + property_exists($json, 'date_time') ); - $this->assertObjectHasAttribute( - 'fallback_value', - $json->date_time + $this->assertTrue( + property_exists($json->date_time, 'fallback_value') ); - $this->assertObjectHasAttribute( - 'timestamp', - $json->date_time + $this->assertTrue( + property_exists($json->date_time, 'timestamp') ); $this->assertEquals( diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDocumentTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDocumentTest.php index 90f0026..4149892 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDocumentTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterDocumentTest.php @@ -25,9 +25,8 @@ public function test__construct() $json->type ); - $this->assertObjectHasAttribute( - 'media', - $json + $this->assertTrue( + property_exists($json, 'media') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterImageTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterImageTest.php index 971982f..aec3d87 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterImageTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterImageTest.php @@ -25,9 +25,8 @@ public function test__construct() $json->type ); - $this->assertObjectHasAttribute( - 'media', - $json + $this->assertTrue( + property_exists($json, 'media') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterPayloadTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterPayloadTest.php index 9a28f87..c0cf584 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterPayloadTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterPayloadTest.php @@ -18,9 +18,8 @@ public function test__construct() $json->type ); - $this->assertObjectHasAttribute( - 'payload', - $json + $this->assertTrue( + property_exists($json, 'payload') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterTextTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterTextTest.php index 42924b0..cba9f34 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterTextTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterTextTest.php @@ -19,9 +19,8 @@ public function test__construct() $json->type ); - $this->assertObjectHasAttribute( - 'text', - $json + $this->assertTrue( + property_exists($json, 'text') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterVideoTest.php b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterVideoTest.php index 0572fb7..d8364d6 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterVideoTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/ComponentParameterVideoTest.php @@ -25,9 +25,8 @@ public function test__construct() $json->type ); - $this->assertObjectHasAttribute( - 'media', - $json + $this->assertTrue( + property_exists($json, 'media') ); } } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/LanguageTest.php b/tests/CMText/RichContent/Templates/Whatsapp/LanguageTest.php index b8b0ad7..8a8b032 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/LanguageTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/LanguageTest.php @@ -15,14 +15,18 @@ public function testJsonSerialize() json_encode($language) ); - $this->assertObjectHasAttribute( - 'code', - json_decode( json_encode($language) ) + $this->assertTrue( + property_exists( + json_decode( json_encode($language) ), + 'code' + ) ); - $this->assertObjectHasAttribute( - 'policy', - json_decode( json_encode($language) ) + $this->assertTrue( + property_exists( + json_decode( json_encode($language) ), + 'policy' + ) ); } diff --git a/tests/CMText/RichContent/Templates/Whatsapp/WhatsappTemplateTest.php b/tests/CMText/RichContent/Templates/Whatsapp/WhatsappTemplateTest.php index ec13f1e..6d86539 100644 --- a/tests/CMText/RichContent/Templates/Whatsapp/WhatsappTemplateTest.php +++ b/tests/CMText/RichContent/Templates/Whatsapp/WhatsappTemplateTest.php @@ -102,9 +102,8 @@ public function testTemplateWithoutComponents() json_encode($whatsappTemplate) ); - $this->assertObjectHasAttribute( - 'components', - $json->whatsapp + $this->assertTrue( + property_exists($json->whatsapp, 'components') ); } } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 0ec5513..08ec865 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -168,24 +168,20 @@ public function testWithTemplate() $json = json_decode(json_encode($message)); - $this->assertObjectHasAttribute( - 'richContent', - $json + $this->assertTrue( + property_exists($json, 'richContent') ); - $this->assertObjectHasAttribute( - 'conversation', - $json->richContent + $this->assertTrue( + property_exists($json->richContent, 'conversation') ); - $this->assertObjectHasAttribute( - 'template', - $json->richContent->conversation[0] + $this->assertTrue( + property_exists($json->richContent->conversation[0], 'template') ); - $this->assertObjectHasAttribute( - 'whatsapp', - $json->richContent->conversation[0]->template + $this->assertTrue( + property_exists($json->richContent->conversation[0]->template, 'whatsapp') ); } @@ -221,24 +217,20 @@ public function testWithPayment() $json = json_decode(json_encode($message)); - $this->assertObjectHasAttribute( - 'richContent', - $json + $this->assertTrue( + property_exists($json, 'richContent') ); - $this->assertObjectHasAttribute( - 'conversation', - $json->richContent + $this->assertTrue( + property_exists($json->richContent, 'conversation') ); - $this->assertObjectHasAttribute( - 'payment', - $json->richContent->conversation[0] + $this->assertTrue( + property_exists($json->richContent->conversation[0], 'payment') ); - $this->assertObjectHasAttribute( - 'lineItems', - $json->richContent->conversation[0]->payment + $this->assertTrue( + property_exists($json->richContent->conversation[0]->payment, 'lineItems') ); } diff --git a/tests/RichMessageTest.php b/tests/RichMessageTest.php index 89c2a01..e446f65 100644 --- a/tests/RichMessageTest.php +++ b/tests/RichMessageTest.php @@ -29,9 +29,8 @@ public function testInitializeText() $json = $richText->jsonSerialize(); - $this->assertObjectHasAttribute( - 'text', - $json + $this->assertTrue( + property_exists($json, 'text') ); } @@ -71,30 +70,24 @@ public function testInitializeCard() $json = json_decode( json_encode($richCard) ); - $this->assertObjectHasAttribute( - 'text', - $json + $this->assertTrue( + property_exists($json, 'text') ); - $this->assertObjectHasAttribute( - 'header', - $json + $this->assertTrue( + property_exists($json, 'header') ); - $this->assertObjectHasAttribute( - 'media', - $json + $this->assertTrue( + property_exists($json, 'media') ); - $this->assertObjectHasAttribute( - 'mediaName', - $json->media + $this->assertTrue( + property_exists($json->media, 'mediaName') ); - $this->assertObjectHasAttribute( - 'mediaUri', - $json->media + $this->assertTrue( + property_exists($json->media, 'mediaUri') ); - $this->assertObjectHasAttribute( - 'mimeType', - $json->media + $this->assertTrue( + property_exists($json->media, 'mimeType') ); } @@ -135,23 +128,20 @@ public function testInitializeCarousel() $json = json_decode( json_encode($carousel) ); - $this->assertObjectHasAttribute( - 'carousel', - $json + $this->assertTrue( + property_exists($json, 'carousel') ); - $this->assertObjectHasAttribute( - 'cardWidth', - $json->carousel + $this->assertTrue( + property_exists($json->carousel, 'cardWidth') ); $this->assertEquals( \CMText\RichContent\Messages\CarouselCardWidth::MEDIUM, $json->carousel->cardWidth ); - $this->assertObjectHasAttribute( - 'cards', - $json->carousel + $this->assertTrue( + property_exists($json->carousel, 'cards') ); $this->assertCount( 2, @@ -178,22 +168,18 @@ public function testInitializeMedia() $json = json_decode( json_encode($media) ); - $this->assertObjectHasAttribute( - 'media', - $json + $this->assertTrue( + property_exists($json, 'media') ); - $this->assertObjectHasAttribute( - 'mediaName', - $json->media + $this->assertTrue( + property_exists($json->media, 'mediaName') ); - $this->assertObjectHasAttribute( - 'mediaUri', - $json->media + $this->assertTrue( + property_exists($json->media, 'mediaUri') ); - $this->assertObjectHasAttribute( - 'mimeType', - $json->media + $this->assertTrue( + property_exists($json->media, 'mimeType') ); } @@ -256,22 +242,18 @@ public function testInitializeLocationPush() $json = json_decode( json_encode($location) ); - $this->assertObjectHasAttribute( - 'location', - $json + $this->assertTrue( + property_exists($json, 'location') ); - $this->assertObjectHasAttribute( - 'label', - $json->location + $this->assertTrue( + property_exists($json->location, 'label') ); - $this->assertObjectHasAttribute( - 'searchQuery', - $json->location + $this->assertTrue( + property_exists($json->location, 'searchQuery') ); - $this->assertObjectNotHasAttribute( - 'radius', - $json->location + $this->assertFalse( + property_exists($json->location, 'radius') ); @@ -295,26 +277,21 @@ public function testInitializeLocationPush() $json = json_decode( json_encode($location) ); - $this->assertObjectHasAttribute( - 'location', - $json + $this->assertTrue( + property_exists($json, 'location') ); - $this->assertObjectHasAttribute( - 'latitude', - $json->location + $this->assertTrue( + property_exists($json->location, 'latitude') ); - $this->assertObjectHasAttribute( - 'longitude', - $json->location + $this->assertTrue( + property_exists($json->location, 'longitude') ); - $this->assertObjectHasAttribute( - 'label', - $json->location + $this->assertTrue( + property_exists($json->location, 'label') ); - $this->assertObjectHasAttribute( - 'radius', - $json->location + $this->assertTrue( + property_exists($json->location, 'radius') ); } @@ -354,17 +331,15 @@ public function testInitializeContactsMessage() $json = json_decode(json_encode($contactsMessage)); - $this->assertObjectHasAttribute( - 'contacts', - $json + $this->assertTrue( + property_exists($json, 'contacts') ); $this->assertCount( 2, $json->contacts ); - $this->assertObjectHasAttribute( - 'org', - $json->contacts[0] + $this->assertTrue( + property_exists($json->contacts[0], 'org') ); } } diff --git a/tests/SuggestionsTest.php b/tests/SuggestionsTest.php index 3b40dbf..a0810bc 100644 --- a/tests/SuggestionsTest.php +++ b/tests/SuggestionsTest.php @@ -8,14 +8,16 @@ class SuggestionsTest extends TestCase public function testBaseClassProperties() { - $this->assertClassHasAttribute( - 'action', + $suggestionBase = $this->getMockForAbstractClass( \CMText\RichContent\Suggestions\SuggestionBase::class ); - $this->assertClassHasAttribute( - 'label', - \CMText\RichContent\Suggestions\SuggestionBase::class + $this->assertTrue( + property_exists($suggestionBase, 'action') + ); + + $this->assertTrue( + property_exists($suggestionBase, 'label') ); } @@ -42,26 +44,21 @@ public function testCalendarSuggestion() $json = json_decode( json_encode($calendar) ); - $this->assertObjectHasAttribute( - 'calendar', - $json + $this->assertTrue( + property_exists($json, 'calendar') ); - $this->assertObjectHasAttribute( - 'startTime', - $json->calendar + $this->assertTrue( + property_exists($json->calendar, 'startTime') ); - $this->assertObjectHasAttribute( - 'endTime', - $json->calendar + $this->assertTrue( + property_exists($json->calendar, 'endTime') ); - $this->assertObjectHasAttribute( - 'title', - $json->calendar + $this->assertTrue( + property_exists($json->calendar, 'title') ); - $this->assertObjectHasAttribute( - 'description', - $json->calendar + $this->assertTrue( + property_exists($json->calendar, 'description') ); } @@ -83,14 +80,12 @@ public function testDialSuggestion() $json = json_decode( json_encode($dial) ); - $this->assertObjectHasAttribute( - 'dial', - $json + $this->assertTrue( + property_exists($json, 'dial') ); - $this->assertObjectHasAttribute( - 'PhoneNumber', - $json->dial + $this->assertTrue( + property_exists($json->dial, 'PhoneNumber') ); } @@ -111,9 +106,11 @@ public function testOpenUrlSuggestion() $openUrl ); - $this->assertObjectHasAttribute( - 'url', - json_decode( json_encode($openUrl) ) + $this->assertTrue( + property_exists( + json_decode( json_encode($openUrl) ), + 'url' + ) ); } @@ -133,9 +130,11 @@ public function testReplySuggestion() $reply ); - $this->assertObjectHasAttribute( - 'postbackdata', - json_decode( json_encode($reply) ) + $this->assertTrue( + property_exists( + json_decode( json_encode($reply) ), + 'postbackdata' + ) ); } @@ -160,26 +159,21 @@ public function testViewLocationSuggestion() $json = json_decode( json_encode($viewStaticLocation) ); - $this->assertObjectHasAttribute( - 'viewLocation', - $json + $this->assertTrue( + property_exists($json, 'viewLocation') ); - $this->assertObjectHasAttribute( - 'latitude', - $json->viewLocation + $this->assertTrue( + property_exists($json->viewLocation, 'latitude') ); - $this->assertObjectHasAttribute( - 'longitude', - $json->viewLocation + $this->assertTrue( + property_exists($json->viewLocation, 'longitude') ); - $this->assertObjectHasAttribute( - 'label', - $json->viewLocation + $this->assertTrue( + property_exists($json->viewLocation, 'label') ); - $this->assertObjectNotHasAttribute( - 'radius', - $json->viewLocation + $this->assertFalse( + property_exists($json->viewLocation, 'radius') ); @@ -201,22 +195,18 @@ public function testViewLocationSuggestion() $json = json_decode( json_encode($viewDynamicLocation) ); - $this->assertObjectHasAttribute( - 'viewLocation', - $json + $this->assertTrue( + property_exists($json, 'viewLocation') ); - $this->assertObjectHasAttribute( - 'label', - $json->viewLocation + $this->assertTrue( + property_exists($json->viewLocation, 'label') ); - $this->assertObjectHasAttribute( - 'searchQuery', - $json->viewLocation + $this->assertTrue( + property_exists($json->viewLocation, 'searchQuery') ); - $this->assertObjectHasAttribute( - 'radius', - $json->viewLocation + $this->assertTrue( + property_exists($json->viewLocation, 'radius') ); }