diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 447283b71..626bb5a77 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -17,7 +17,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - php: [ 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 ] + php: [ '7.3', '7.4', '8.0', '8.1' ] env: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: @@ -46,7 +46,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@2.15.0 with: - php-version: '7.4' + php-version: '8.1' id: php - name: Build Release Artifacts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d5f9efbe9..6e91f544b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,7 +57,7 @@ Please note that we utilize the [Gitflow Workflow](https://www.atlassian.com/git ##### Prerequisites ##### -- PHP 5.6, 7.0, 7.1, 7.2, 7.3 or 7.4 +- PHP version 7.3, 7.4, 8.0, or 8.1 ##### Initial setup: ##### diff --git a/Makefile b/Makefile index b7438ba82..d482e48a7 100644 --- a/Makefile +++ b/Makefile @@ -22,11 +22,7 @@ ci-install: clean test: vendor/bin/phpunit test/unit --filter test* vendor/bin/phpcs lib/*/* - -ifeq ($(shell expr $(php_version) \>= 7.1), 1) - composer require --dev phpstan/phpstan vendor/bin/phpstan analyse --no-progress --level 1 lib test -endif test-integ: test vendor/bin/phpunit test --filter test* @@ -38,4 +34,4 @@ test-docker: dependencies=highest version=$(version) bash ./prism.sh bundle: ci-install - zip -r sendgrid-php.zip . -x \*.git\* \*composer.json\* \*scripts\* \*test\* \*.travis.yml\* \*prism\* + zip -r sendgrid-php.zip . -x \*.git\* \*composer.json\* \*scripts\* \*test\* \*prism\* diff --git a/README.md b/README.md index 5a233ee84..07dfb3c28 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ We appreciate your continued support, thank you! ## Prerequisites -- PHP version 5.6, 7.0, 7.1, 7.2, 7.3, or 7.4 +- PHP version 7.3, 7.4, 8.0, or 8.1 - The Twilio SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-php) to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check out [our pricing](https://sendgrid.com/pricing?source=sendgrid-php). - For SMS messages, you will need a free [Twilio account](https://www.twilio.com/try-twilio?source=sendgrid-php). diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 000000000..6de142cea --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,8 @@ +# Upgrade Guide + +_MAJOR version bumps will have upgrade notes posted here._ + +[2022-05-04] 7.x.x to 8.x.x +--------------------------- + +### CHANGED - Drop support for PHP versions 5.6, 7.0, 7.1, and 7.2 which are EOL. diff --git a/composer.json b/composer.json index f9e25e347..047750f0d 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "grid" ], "require": { - "php": ">=5.6", + "php": ">=7.3", "sendgrid/php-http-client": "~3.10", "starkbank/ecdsa": "0.*", "ext-curl": "*", @@ -22,9 +22,10 @@ "ext-openssl": "*" }, "require-dev": { - "phpunit/phpunit": "^5.7.9 || ^6.4.3", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "3.*", - "swaggest/json-diff": "^3.4" + "swaggest/json-diff": "^3.4", + "phpstan/phpstan": "^1.5" }, "replace": { "sendgrid/sendgrid-php": "*" diff --git a/test/BaseTestClass.php b/test/BaseTestClass.php index 1b752ee07..0c1f2a6cb 100644 --- a/test/BaseTestClass.php +++ b/test/BaseTestClass.php @@ -3,11 +3,11 @@ * This file contains the base class for testing the request object * generation for a /mail/send API call */ + namespace SendGrid\Tests; use PHPUnit\Framework\TestCase; use SendGrid; -use Swaggest\JsonDiff\Exception; use Swaggest\JsonDiff\JsonDiff; use Swaggest\JsonDiff\JsonPatch; @@ -27,9 +27,9 @@ class BaseTestClass extends TestCase /** * This method is run before the classes are initialised * - * @return null + * @return void */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$apiKey = 'SENDGRID_API_KEY'; self::$sg = new SendGrid(self::$apiKey); diff --git a/test/integration/Helpers/Stats/StatsTest.php b/test/integration/Helpers/Stats/StatsTest.php index 6f495d507..6fb9af31c 100644 --- a/test/integration/Helpers/Stats/StatsTest.php +++ b/test/integration/Helpers/Stats/StatsTest.php @@ -1,8 +1,9 @@ assertEquals($expectedGlobal, $userStats->getGlobal()); $this->assertEquals($expectedCategory, $userStats->getCategory($expectedCategory['categories'])); @@ -48,7 +50,6 @@ public function testGetValues( * @param array $expectedSum * @param array $expectedSubuserMonthly * @dataProvider invalidValues - * @expectedException \Exception */ public function testGetValuesFail( $expectedGlobal, @@ -56,7 +57,9 @@ public function testGetValuesFail( $expectedSubuser, $expectedSum, $expectedSubuserMonthly - ) { + ) + { + $this->expectException(\Exception::class); $this->testGetValues( $expectedGlobal, $expectedCategory, diff --git a/test/unit/AsmTest.php b/test/unit/AsmTest.php index ed83a7b07..93b7f4a23 100644 --- a/test/unit/AsmTest.php +++ b/test/unit/AsmTest.php @@ -2,12 +2,14 @@ /** * This file tests Asm. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\Asm; use SendGrid\Mail\GroupId; use SendGrid\Mail\GroupsToDisplay; +use SendGrid\Mail\TypeException; /** * This file tests Asm. @@ -39,23 +41,21 @@ public function testSetGroupsToDisplay() $this->assertSame([1, 2, 3, 4], $asm->getGroupsToDisplay()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$groups_to_display" must be an instance of SendGrid\Mail\GroupsToDisplay or an array. - */ public function testSetGroupToDisplayOnInvalidValue() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$groups_to_display" must be an instance of SendGrid\\\Mail\\\GroupsToDisplay or an array/'); + $asm = new Asm(123456, [1, 2, 3, 4]); $asm->setGroupsToDisplay('invalid_array'); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$group_id" must be an instance of SendGrid\Mail\GroupId or an integer. - */ public function testSetGroupIdOnInvalidGroupId() { - $asm = new Asm(123456, [1,2,3,4]); + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$group_id" must be an instance of SendGrid\\\Mail\\\GroupId or an integer/'); + + $asm = new Asm(123456, [1, 2, 3, 4]); $asm->setGroupId('invalid_group_id'); } } diff --git a/test/unit/BatchIdTest.php b/test/unit/BatchIdTest.php index 0a7abe6f0..ca89d6a67 100644 --- a/test/unit/BatchIdTest.php +++ b/test/unit/BatchIdTest.php @@ -2,10 +2,12 @@ /** * This file tests BatchId. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\BatchId; +use SendGrid\Mail\TypeException; /** * This file tests BatchId. @@ -30,14 +32,13 @@ public function testSetBatchId() $this->assertSame('this_is_batch_id', $batchId->getBatchId()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$batch_id" must be a string. - */ public function testSetBatchIdOnInvalidBatchId() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$batch_id" must be a string/'); + $batch_id = new BatchId(); - $batch_id->setBatchId(['invalid_batch_id']); + $batch_id->setBatchId(123); } public function testJsonSerialize() diff --git a/test/unit/BccSettingsTest.php b/test/unit/BccSettingsTest.php index a000bed1b..55ef665c3 100644 --- a/test/unit/BccSettingsTest.php +++ b/test/unit/BccSettingsTest.php @@ -2,10 +2,12 @@ /** * This file tests BccSettings. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\BccSettings; +use SendGrid\Mail\TypeException; /** * This file tests BccSettings. @@ -31,24 +33,22 @@ public function testSetEmail() $this->assertSame('dx@sendgrid.com', $bccSettings->getEmail()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$email" must be a valid email address. - */ public function testSetEmailOnInvalidEmailFormat() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$email" must be a valid email address/'); + $bccSettings = new BccSettings(); $bccSettings->setEmail('invalid_email_address'); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$email" must be a string. - */ public function testSetEmailOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$email" must be a string/'); + $bccSettings = new BccSettings(); - $bccSettings->setEmail(['invalid_type']); + $bccSettings->setEmail(123); } public function testSetEnable() @@ -59,12 +59,11 @@ public function testSetEnable() $this->assertTrue($bccSettings->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $bccSettings = new BccSettings(); $bccSettings->setEnable('invalid_bool_type'); } diff --git a/test/unit/BypassBounceManagementTest.php b/test/unit/BypassBounceManagementTest.php index 9d28e4e35..ee7cfd352 100644 --- a/test/unit/BypassBounceManagementTest.php +++ b/test/unit/BypassBounceManagementTest.php @@ -2,10 +2,12 @@ /** * This file tests BypassBounceManagement. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\BypassBounceManagement; +use SendGrid\Mail\TypeException; /** * This file tests BypassBounceManagement. @@ -30,12 +32,11 @@ public function testSetEnable() $this->assertTrue($bypassBounceManagement->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $bypassBounceManagement = new BypassBounceManagement(); $bypassBounceManagement->setEnable('invalid_bool_type'); } diff --git a/test/unit/BypassListManagementTest.php b/test/unit/BypassListManagementTest.php index 00d44af52..77fb16c57 100644 --- a/test/unit/BypassListManagementTest.php +++ b/test/unit/BypassListManagementTest.php @@ -2,10 +2,12 @@ /** * This file tests BypassListManagement. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\BypassListManagement; +use SendGrid\Mail\TypeException; /** * This file tests BypassListManagement. @@ -30,12 +32,11 @@ public function testSetEnable() $this->assertTrue($bypassListManagement->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $bypassListManagement = new BypassListManagement(); $bypassListManagement->setEnable('invalid_bool_type'); } diff --git a/test/unit/BypassSpamManagementTest.php b/test/unit/BypassSpamManagementTest.php index 6160d6214..ae9d432bf 100644 --- a/test/unit/BypassSpamManagementTest.php +++ b/test/unit/BypassSpamManagementTest.php @@ -2,10 +2,12 @@ /** * This file tests BypassSpamManagement. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\BypassSpamManagement; +use SendGrid\Mail\TypeException; /** * This file tests BypassSpamManagement. @@ -30,12 +32,11 @@ public function testSetEnable() $this->assertTrue($bypassSpamManagement->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $bypassSpamManagement = new BypassSpamManagement(); $bypassSpamManagement->setEnable('invalid_bool_type'); } diff --git a/test/unit/BypassUnsubscribeManagementTest.php b/test/unit/BypassUnsubscribeManagementTest.php index 82da849cf..19e865599 100644 --- a/test/unit/BypassUnsubscribeManagementTest.php +++ b/test/unit/BypassUnsubscribeManagementTest.php @@ -2,10 +2,12 @@ /** * This file tests BypassUnsubscribeManagement. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\BypassUnsubscribeManagement; +use SendGrid\Mail\TypeException; /** * This file tests BypassUnsubscribeManagement. @@ -30,12 +32,11 @@ public function testSetEnable() $this->assertTrue($bypassUnsubscribeManagement->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $bypassUnsubscribeManagement = new BypassUnsubscribeManagement(); $bypassUnsubscribeManagement->setEnable('invalid_bool_type'); } diff --git a/test/unit/CategoryTest.php b/test/unit/CategoryTest.php index 82df88c69..fc36c6c0c 100644 --- a/test/unit/CategoryTest.php +++ b/test/unit/CategoryTest.php @@ -2,10 +2,12 @@ /** * This file tests Category. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\Category; +use SendGrid\Mail\TypeException; /** * This file tests Category. @@ -30,14 +32,13 @@ public function testSetCategory() $this->assertSame('category', $category->getCategory()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$category" must be a string. - */ public function testSetCategoryOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$category" must be a string/'); + $category = new Category(); - $category->setCategory(['invalid_category']); + $category->setCategory(123); } public function testJsonSerialize() diff --git a/test/unit/ClickTrackingTest.php b/test/unit/ClickTrackingTest.php index 84f6e3604..232f71b94 100644 --- a/test/unit/ClickTrackingTest.php +++ b/test/unit/ClickTrackingTest.php @@ -2,10 +2,12 @@ /** * This file tests ClickTracking. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\ClickTracking; +use SendGrid\Mail\TypeException; /** * This file tests ClickTracking. @@ -31,12 +33,11 @@ public function testSetEnable() $this->assertTrue($clickTracking->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $clickTracking = new ClickTracking(); $clickTracking->setEnable('invalid_bool'); } @@ -49,12 +50,11 @@ public function testSetEnableText() $this->assertTrue($clickTracking->getEnableText()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable_text" must be a boolean. - */ public function testSetEnableTextOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable_text" must be a boolean/'); + $clickTracking = new ClickTracking(); $clickTracking->setEnableText('invalid_bool'); } diff --git a/test/unit/ContentTest.php b/test/unit/ContentTest.php index ece3be28f..4eb29d1c2 100644 --- a/test/unit/ContentTest.php +++ b/test/unit/ContentTest.php @@ -2,10 +2,12 @@ /** * This file tests Content. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\Content; +use SendGrid\Mail\TypeException; /** * This file tests Content. @@ -31,14 +33,13 @@ public function testSetType() $this->assertSame('type', $content->getType()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$type" must be a string. - */ public function testSetTypeOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$type" must be a string/'); + $content = new Content(); - $content->setType(['type']); + $content->setType(123); } public function testSetValue() @@ -49,13 +50,12 @@ public function testSetValue() $this->assertSame('value', $content->getValue()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$value" must be a string. - */ public function testSetValueOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$value" must be a string/'); + $content = new Content(); - $content->setValue(['value']); + $content->setValue(123); } } diff --git a/test/unit/CustomArgTest.php b/test/unit/CustomArgTest.php index f7f3b58b8..a2aae232d 100644 --- a/test/unit/CustomArgTest.php +++ b/test/unit/CustomArgTest.php @@ -2,10 +2,12 @@ /** * This file tests CustomArg. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\CustomArg; +use SendGrid\Mail\TypeException; /** * This file tests CustomArg. @@ -31,14 +33,13 @@ public function testSetKey() $this->assertSame('key', $customArg->getKey()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$key" must be a string. - */ public function testSetKeyOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$key" must be a string/'); + $customArg = new CustomArg(); - $customArg->setKey(['key']); + $customArg->setKey(123); } public function testSetValue() @@ -49,13 +50,12 @@ public function testSetValue() $this->assertSame('value', $customArg->getValue()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$value" must be a string. - */ public function testSetValueOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$value" must be a string/'); + $customArg = new CustomArg(); - $customArg->setValue(['value']); + $customArg->setValue(123); } } diff --git a/test/unit/EmailAddressTest.php b/test/unit/EmailAddressTest.php index 5e4ecbca5..162d64e5a 100644 --- a/test/unit/EmailAddressTest.php +++ b/test/unit/EmailAddressTest.php @@ -32,7 +32,7 @@ class EmailAddressTest extends TestCase /** * Use a fresh instance in every test */ - public function setUp() + public function setUp(): void { $this->email = new EmailAddress(); } @@ -660,24 +660,22 @@ public function testSetEmailAddress() $this->assertSame('dx@sendgrid.com', $emailAddress->getEmail()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$emailAddress" must be a valid email address. - */ public function testSetEmailAddressOnInvalidFormat() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$emailAddress" must be a valid email address/'); + $emailAddress = new EmailAddress(); $emailAddress->setEmailAddress('invalid_email_address_format'); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$emailAddress" must be a string. - */ public function testSetEmailAddressOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$emailAddress" must be a string/'); + $emailAddress = new EmailAddress(); - $emailAddress->setEmailAddress(['dx@sendgrid.com']); + $emailAddress->setEmailAddress(123); } public function testSetName() @@ -688,14 +686,13 @@ public function testSetName() $this->assertSame('Elmer', $emailAddress->getName()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$name" must be a string. - */ public function testSetNameOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$name" must be a string/'); + $emailAddress = new EmailAddress(); - $emailAddress->setName(['Elmer']); + $emailAddress->setName(123); } public function testSetSubstitutions() @@ -706,12 +703,11 @@ public function testSetSubstitutions() $this->assertSame(['key' => 'value'], $emailAddress->getSubstitutions()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$substitutions" must be an array. - */ public function testSetSubstitutionsOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$substitutions" must be an array/'); + $emailAddress = new EmailAddress(); $emailAddress->setSubstitutions('invalid_type'); } @@ -726,13 +722,12 @@ public function testSetSubject() $this->assertSame('subject', $subject->getSubject()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$subject" must be a string. - */ public function testSetSubjectOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$subject" must be a string/'); + $emailAddress = new EmailAddress(); - $emailAddress->setSubject(['invalid_subject']); + $emailAddress->setSubject(123); } } diff --git a/test/unit/EventWebhookTest.php b/test/unit/EventWebhookTest.php index c84546ed2..2ab098d27 100644 --- a/test/unit/EventWebhookTest.php +++ b/test/unit/EventWebhookTest.php @@ -17,7 +17,7 @@ class EventWebhookTest extends TestCase private static $TIMESTAMP; private static $PAYLOAD; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIv IW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=='; diff --git a/test/unit/FooterTest.php b/test/unit/FooterTest.php index c3d0d6778..49615e065 100644 --- a/test/unit/FooterTest.php +++ b/test/unit/FooterTest.php @@ -2,10 +2,12 @@ /** * This file tests Footer. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\Footer; +use SendGrid\Mail\TypeException; /** * This file tests Footer. @@ -32,12 +34,11 @@ public function testSetEnable() $this->assertTrue($footer->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $footer = new Footer(); $footer->setEnable('invalid_bool'); } @@ -50,14 +51,13 @@ public function testSetText() $this->assertSame('footer_text', $footer->getText()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$text" must be a string. - */ public function testSetTextOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$text" must be a string/'); + $footer = new Footer(); - $footer->setText(['footer_text']); + $footer->setText(123); } public function testSetHtml() @@ -68,13 +68,12 @@ public function testSetHtml() $this->assertSame('footer_html', $footer->getHtml()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$html" must be a string. - */ public function testSetHtmlOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$html" must be a string/'); + $footer = new Footer(); - $footer->setHtml(['footer_html']); + $footer->setHtml(123); } } diff --git a/test/unit/GanalyticsTest.php b/test/unit/GanalyticsTest.php index 367fc0494..0c383603b 100644 --- a/test/unit/GanalyticsTest.php +++ b/test/unit/GanalyticsTest.php @@ -2,10 +2,12 @@ /** * This file tests Ganalytics. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\Ganalytics; +use SendGrid\Mail\TypeException; /** * This file tests Ganalytics. @@ -35,12 +37,11 @@ public function testSetEnable() $this->assertTrue($ganalytics->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $ganalytics = new Ganalytics(); $ganalytics->setEnable('invalid_bool'); } @@ -53,14 +54,13 @@ public function testSetCampaignContent() $this->assertSame('utm_content', $ganalytics->getCampaignContent()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$utm_content" must be a string. - */ public function testSetCampaignContentOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$utm_content" must be a string/'); + $ganalytics = new Ganalytics(); - $ganalytics->setCampaignContent(['invalid_utm_content']); + $ganalytics->setCampaignContent(123); } public function testSetCampaignTerm() @@ -71,14 +71,13 @@ public function testSetCampaignTerm() $this->assertSame('utm_term', $ganalytics->getCampaignTerm()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$utm_term" must be a string. - */ public function testSetCampaignTermOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$utm_term" must be a string/'); + $ganalytics = new Ganalytics(); - $ganalytics->setCampaignTerm(['invalid_utm_term']); + $ganalytics->setCampaignTerm(123); } public function testSetCampaignMedium() @@ -89,14 +88,13 @@ public function testSetCampaignMedium() $this->assertSame('utm_medium', $ganalytics->getCampaignMedium()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$utm_medium" must be a string. - */ public function testSetCampaignMediumOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$utm_medium" must be a string/'); + $ganalytics = new Ganalytics(); - $ganalytics->setCampaignMedium(['invalid_utm_medium']); + $ganalytics->setCampaignMedium(123); } public function testSetCampaignSource() @@ -107,14 +105,13 @@ public function testSetCampaignSource() $this->assertSame('utm_campaign', $ganalytics->getCampaignSource()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$utm_source" must be a string. - */ public function testSetCampaignSourceOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$utm_source" must be a string/'); + $ganalytics = new Ganalytics(); - $ganalytics->setCampaignSource(['invalid_utm_campaign']); + $ganalytics->setCampaignSource(123); } public function testSetCampaignName() @@ -125,13 +122,12 @@ public function testSetCampaignName() $this->assertSame('utm_campaign_name', $ganalytics->getCampaignName()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$utm_campaign" must be a string. - */ public function testSetCampaignNameOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$utm_campaign" must be a string/'); + $ganalytics = new Ganalytics(); - $ganalytics->setCampaignName(['invalid_utm_campaign_name']); + $ganalytics->setCampaignName(123); } } diff --git a/test/unit/GroupIdTest.php b/test/unit/GroupIdTest.php index 16c54440b..c5fb5cb34 100644 --- a/test/unit/GroupIdTest.php +++ b/test/unit/GroupIdTest.php @@ -2,10 +2,12 @@ /** * This file tests GroupId. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\GroupId; +use SendGrid\Mail\TypeException; /** * This file tests GroupId. @@ -29,12 +31,11 @@ public function testSetGroupId() $this->assertSame(123456, $groupId->getGroupId()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$group_id" must be an integer. - */ public function testSetGroupIdOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$group_id" must be an integer/'); + $groupId = new GroupId(); $groupId->setGroupId('invalid_group_id'); } diff --git a/test/unit/GroupsToDisplayTest.php b/test/unit/GroupsToDisplayTest.php index 010e5efb6..9296295d3 100644 --- a/test/unit/GroupsToDisplayTest.php +++ b/test/unit/GroupsToDisplayTest.php @@ -47,12 +47,11 @@ public function testSetGroupsToDisplay() $this->assertSame([123456], $groupsToDisplay->getGroupsToDisplay()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$groups_to_display" must be an array. - */ public function testSetGroupsToDisplayOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$groups_to_display" must be an array/'); + $groupsToDisplay = new GroupsToDisplay(); $groupsToDisplay->setGroupsToDisplay('invalid_groups_to_display'); } diff --git a/test/unit/HeaderTest.php b/test/unit/HeaderTest.php index 652746a2a..5e91fae7f 100644 --- a/test/unit/HeaderTest.php +++ b/test/unit/HeaderTest.php @@ -2,10 +2,12 @@ /** * This file tests Header. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\Header; +use SendGrid\Mail\TypeException; /** * This file tests Header. @@ -30,14 +32,13 @@ public function testSetKey() $this->assertSame('Content-Type', $header->getKey()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$key" must be a string. - */ public function testSetKeyOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$key" must be a string/'); + $header = new Header(); - $header->setKey(['Content-Type']); + $header->setKey(123); } public function testSetValue() @@ -48,13 +49,12 @@ public function testSetValue() $this->assertSame('text/plain', $header->getValue()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$value" must be a string. - */ public function testSetValueOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$value" must be a string/'); + $header = new Header(); - $header->setValue(['text/plain']); + $header->setValue(123); } } diff --git a/test/unit/IpPoolNameTest.php b/test/unit/IpPoolNameTest.php index e224d8c21..94b05f177 100644 --- a/test/unit/IpPoolNameTest.php +++ b/test/unit/IpPoolNameTest.php @@ -2,10 +2,12 @@ /** * This file tests IpPoolName. */ + namespace SendGrid\Tests\Unit; use PHPUnit\Framework\TestCase; use SendGrid\Mail\IpPoolName; +use SendGrid\Mail\TypeException; /** * This file tests IpPoolName. @@ -30,14 +32,13 @@ public function testSetIpPoolNme() $this->assertSame('127.0.0.1', $ipPoolName->getIpPoolName()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$ip_pool_name" must be a string. - */ public function testSetIpPoolNmeOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$ip_pool_name" must be a string/'); + $ipPoolName = new IpPoolName(); - $ipPoolName->setIpPoolName(['127.0.0.1']); + $ipPoolName->setIpPoolName(123); } public function testJsonSerialize() diff --git a/test/unit/OpenTrackingTest.php b/test/unit/OpenTrackingTest.php index 2064c787b..0ac46037b 100644 --- a/test/unit/OpenTrackingTest.php +++ b/test/unit/OpenTrackingTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\OpenTracking; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\OpenTracking; +use SendGrid\Mail\TypeException; /** * This class tests OpenTracking. @@ -31,12 +32,11 @@ public function testSetEnable() $this->assertTrue($openTracking->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $openTracking = new OpenTracking(); $openTracking->setEnable('invalid_bool'); } @@ -49,13 +49,12 @@ public function testSetSubstitutionTag() $this->assertSame('substitution_tag', $openTracking->getSubstitutionTag()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$substitution_tag" must be a string. - */ public function testSetSubstitutionTagOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$substitution_tag" must be a string/'); + $openTracking = new OpenTracking(); - $openTracking->setSubstitutionTag(['invalid_substitution_tag']); + $openTracking->setSubstitutionTag(123); } } diff --git a/test/unit/PersonalizationTest.php b/test/unit/PersonalizationTest.php index 5aca0b8d0..9bd35ba4a 100644 --- a/test/unit/PersonalizationTest.php +++ b/test/unit/PersonalizationTest.php @@ -5,16 +5,17 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\From; -use SendGrid\Mail\Personalization; -use SendGrid\Mail\To; -use SendGrid\Mail\Cc; +use PHPUnit\Framework\TestCase; use SendGrid\Mail\Bcc; -use SendGrid\Mail\Header; -use SendGrid\Mail\Subject; +use SendGrid\Mail\Cc; use SendGrid\Mail\CustomArg; +use SendGrid\Mail\From; +use SendGrid\Mail\Header; +use SendGrid\Mail\Personalization; use SendGrid\Mail\SendAt; -use PHPUnit\Framework\TestCase; +use SendGrid\Mail\Subject; +use SendGrid\Mail\To; +use SendGrid\Mail\TypeException; /** * This class tests Personalization. @@ -63,12 +64,11 @@ public function testSetSubject() $this->assertSame('subject', $personalization->getSubject()->getSubject()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$subject" must be an instance of SendGrid\Mail\Subject or a string - */ public function testSetSubjectOnInvalidSubjectClass() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$subject" must be an instance of SendGrid\\\Mail\\\Subject or a string/'); + $personalization = new Personalization(); $personalization->setSubject(false); } @@ -105,12 +105,11 @@ public function testSetSendAt() $this->assertSame(1539363393, $personalization->getSendAt()->getSendAt()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$send_at" must be an instance of "SendGrid\Mail\SendAt" - */ public function testSendAtOnInvalidSendAtClass() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$send_at" must be an instance of "SendGrid\\\Mail\\\SendAt/'); + $personalization = new Personalization(); $personalization->setSendAt('invalid_send_at_class'); } @@ -123,12 +122,11 @@ public function testSetHasDynamicTemplate() $this->assertTrue($personalization->getHasDynamicTemplate()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$has_dynamic_template" must be a boolean. - */ public function testSetHasDynamicTemplateOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$has_dynamic_template" must be a boolean/'); + $personalization = new Personalization(); $personalization->setHasDynamicTemplate('invalid_bool_type'); } diff --git a/test/unit/SandBoxModeTest.php b/test/unit/SandBoxModeTest.php index 61f589e04..656f5dc93 100644 --- a/test/unit/SandBoxModeTest.php +++ b/test/unit/SandBoxModeTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\SandBoxMode; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\SandBoxMode; +use SendGrid\Mail\TypeException; /** * This class tests SandBoxMode. @@ -31,12 +32,11 @@ public function testSetEnable() $this->assertTrue($sandBoxMode->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $sandBoxMode = new SandBoxMode(); $sandBoxMode->setEnable('invalid_bool'); } diff --git a/test/unit/SectionTest.php b/test/unit/SectionTest.php index 503b8bec0..d83bdb742 100644 --- a/test/unit/SectionTest.php +++ b/test/unit/SectionTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\Section; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\Section; +use SendGrid\Mail\TypeException; /** * This class tests Section. @@ -32,12 +33,11 @@ public function testSetKey() $this->assertSame('key', $section->getKey()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$key" must be a string. - */ public function testSetKeyOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$key" must be a string/'); + $section = new Section(); $section->setKey(true); } @@ -50,12 +50,11 @@ public function testSetValue() $this->assertSame('value', $section->getValue()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$value" must be a string. - */ public function testSetValueOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$value" must be a string/'); + $section = new Section(); $section->setValue(true); } diff --git a/test/unit/SendAtTest.php b/test/unit/SendAtTest.php index 1ce9bd60c..0366cafa9 100644 --- a/test/unit/SendAtTest.php +++ b/test/unit/SendAtTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\SendAt; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\SendAt; +use SendGrid\Mail\TypeException; /** * This class tests SendAt. @@ -31,12 +32,11 @@ public function testSendAt() $this->assertSame(1539368762, $sendAt->getSendAt()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$send_at" must be an integer. - */ public function testSendAtOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$send_at" must be an integer/'); + $sendAt = new SendAt(); $sendAt->setSendAt('invalid_int_type'); } diff --git a/test/unit/SpamCheckTest.php b/test/unit/SpamCheckTest.php index 2d0efc33b..e4d90009c 100644 --- a/test/unit/SpamCheckTest.php +++ b/test/unit/SpamCheckTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\SpamCheck; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\SpamCheck; +use SendGrid\Mail\TypeException; /** * This class tests SpamCheck. @@ -33,12 +34,11 @@ public function testSetEnable() $this->assertTrue($spamCheck->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $spamCheck = new SpamCheck(); $spamCheck->setEnable('invalid_bool_type'); } @@ -51,12 +51,11 @@ public function testSetThreshold() $this->assertSame(1, $spamCheck->getThreshold()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$threshold" must be an integer. - */ public function testSetThresholdOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$threshold" must be an integer/'); + $spamCheck = new SpamCheck(); $spamCheck->setThreshold('invalid_int_type'); } @@ -69,12 +68,11 @@ public function testSetPostToUrl() $this->assertSame('http://post-to.url', $spamCheck->getPostToUrl()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$post_to_url" must be a string. - */ public function testSetPostToUrlOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$post_to_url" must be a string/'); + $spamCheck = new SpamCheck(); $spamCheck->setPostToUrl(true); } diff --git a/test/unit/SubjectTest.php b/test/unit/SubjectTest.php index ef0cb7c8f..4c5bcbb4c 100644 --- a/test/unit/SubjectTest.php +++ b/test/unit/SubjectTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\Subject; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\Subject; +use SendGrid\Mail\TypeException; /** * This class tests Subject. @@ -39,12 +40,11 @@ public function testJsonSerialize() $this->assertSame('subject', $subject->jsonSerialize()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$subject" must be a string. - */ public function testSetSubjectOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$subject" must be a string/'); + $subject = new Subject(); $subject->setSubject(true); } diff --git a/test/unit/SubscriptionTrackingTest.php b/test/unit/SubscriptionTrackingTest.php index 9f354545a..bc2aec63a 100644 --- a/test/unit/SubscriptionTrackingTest.php +++ b/test/unit/SubscriptionTrackingTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\SubscriptionTracking; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\SubscriptionTracking; +use SendGrid\Mail\TypeException; /** * This class tests SubscriptionTracking. @@ -34,12 +35,11 @@ public function testSetEnable() $this->assertTrue($subscriptionTracking->getEnable()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$enable" must be a boolean. - */ public function testSetEnableOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$enable" must be a boolean/'); + $subscriptionTracking = new SubscriptionTracking(); $subscriptionTracking->setEnable('invalid_bool_type'); } @@ -52,12 +52,11 @@ public function testSetText() $this->assertSame('text', $subscriptionTracking->getText()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$text" must be a string. - */ public function testSetTextOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$text" must be a string/'); + $subscriptionTracking = new SubscriptionTracking(); $subscriptionTracking->setText(true); } @@ -70,12 +69,11 @@ public function testSetHtml() $this->assertSame('

I am html text

', $subscriptionTracking->getHtml()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$html" must be a string. - */ public function testSetHtmlOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$html" must be a string/'); + $subscriptionTracking = new SubscriptionTracking(); $subscriptionTracking->setHtml(true); } @@ -88,12 +86,11 @@ public function testSetSubstitutionTag() $this->assertSame('sub_tag', $subscriptionTracking->getSubstitutionTag()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$substitution_tag" must be a string. - */ public function testSetSubstitutionTagOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$substitution_tag" must be a string/'); + $subscriptionTracking = new SubscriptionTracking(); $subscriptionTracking->setSubstitutionTag(true); } diff --git a/test/unit/SubstitutionTest.php b/test/unit/SubstitutionTest.php index 668dfb9c0..3bbfc6783 100644 --- a/test/unit/SubstitutionTest.php +++ b/test/unit/SubstitutionTest.php @@ -1,8 +1,10 @@ 'foo'); + $testObject = (object)array('1' => 'foo'); $testNumberInt = 1; $testNumberFloat = 1.0; $testInvalidInput = null; @@ -52,12 +54,11 @@ public function testSetKey() $this->assertSame('key', $substitution->getKey()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$key" must be a string. - */ public function testSetKeyOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$key" must be a string/'); + $substitution = new Substitution(); $substitution->setKey(true); } @@ -70,12 +71,11 @@ public function testSetValue() $this->assertSame('key', $substitution->getValue()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$value" must be an array, object, boolean, string, numeric or integer. - */ public function testSetValueOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$value" must be an array, object, boolean, string, numeric or integer/'); + $substitution = new Substitution(); $substitution->setValue(null); } diff --git a/test/unit/TemplateIdTest.php b/test/unit/TemplateIdTest.php index 0358eefba..33143c00a 100644 --- a/test/unit/TemplateIdTest.php +++ b/test/unit/TemplateIdTest.php @@ -5,8 +5,9 @@ namespace SendGrid\Tests\Unit; -use SendGrid\Mail\TemplateId; use PHPUnit\Framework\TestCase; +use SendGrid\Mail\TemplateId; +use SendGrid\Mail\TypeException; /** * This class tests TemplateId. @@ -30,12 +31,11 @@ public function testSetTemplateId() $this->assertSame('template_id', $templateId->getTemplateId()); } - /** - * @expectedException \SendGrid\Mail\TypeException - * @expectedExceptionMessage "$template_id" must be a string. - */ public function testSetTemplateIdOnInvalidType() { + $this->expectException(TypeException::class); + $this->expectExceptionMessageMatches('/"\$template_id" must be a string/'); + $templateId = new TemplateId(); $templateId->setTemplateId(true); } diff --git a/test/unit/TwilioEmailTest.php b/test/unit/TwilioEmailTest.php index a9a03a837..d77803c46 100644 --- a/test/unit/TwilioEmailTest.php +++ b/test/unit/TwilioEmailTest.php @@ -17,12 +17,10 @@ class TwilioEmailTest extends BaseTestClass public function testCanConnectToTwilioEmailApi() { $mail = new \TwilioEmail('username', 'password'); - $headers = [ - 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=', - ]; + $authHeader = 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ='; $this->assertEquals('https://email.twilio.com', $mail->client->getHost()); - $this->assertArraySubset($headers, $mail->client->getHeaders()); + $this->assertContains($authHeader, $mail->client->getHeaders()); $mail = new \TwilioEmail('username', 'password', ['host' => 'https://api.test.com']); $this->assertEquals('https://api.test.com', $mail->client->getHost());