From e2a9c5ebee054dcdb638bcce7b4a247052e5681f Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Mon, 7 Feb 2022 15:50:25 -0600 Subject: [PATCH 01/10] chore: upgrade supported language versions --- .github/workflows/test-and-deploy.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 89ff4240..c21ac557 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: [ '5.6', '7.0', '7.1', '7.2', '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/README.md b/README.md index 46ad342f..c289ee7b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,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 5.6, 7.0, 7.1, 7.2, 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). From bb1ff44cbb88ec58b5286b2a9431a0e42613ed49 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Feb 2022 14:49:28 -0800 Subject: [PATCH 02/10] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b67d5c..0ec51c0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +[2022-02-09] Version 7.11.4 +--------------------------- +**Library - Chore** +- [PR #1079](https://github.com/sendgrid/sendgrid-php/pull/1079): add deploy job to test and deploy gh workflow. Thanks to [@Hunga1](https://github.com/Hunga1)! + + [2022-01-26] Version 7.11.3 --------------------------- **Library - Chore** From daa685fb1ede20c7bd907c4d9cc4f66d2b49e10c Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Feb 2022 14:49:28 -0800 Subject: [PATCH 03/10] Release 7.11.4 --- README.md | 4 ++-- lib/BaseSendGridClientInterface.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c289ee7b..fa624dc1 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ Add Twilio SendGrid to your `composer.json` file. If you are not using [Composer ### Alternative: Install package from zip -If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.3/sendgrid-php.zip)**. +If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.4/sendgrid-php.zip)**. -[**⬇︎ Download Packaged Library ⬇︎**](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.3/sendgrid-php.zip) +[**⬇︎ Download Packaged Library ⬇︎**](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.4/sendgrid-php.zip) Previous versions of the library can be downloaded directly from [GitHub](https://github.com/sendgrid/sendgrid-php/releases). diff --git a/lib/BaseSendGridClientInterface.php b/lib/BaseSendGridClientInterface.php index c87909dd..846d38cc 100644 --- a/lib/BaseSendGridClientInterface.php +++ b/lib/BaseSendGridClientInterface.php @@ -12,7 +12,7 @@ abstract class BaseSendGridClientInterface { /** @var string SendGrid API library version */ - const VERSION = '7.11.3'; + const VERSION = '7.11.4'; /** @var Client SendGrid HTTP Client library */ public $client; From 26d5e1e057fca3a23bd84cc5ce75b5aa8598ee71 Mon Sep 17 00:00:00 2001 From: Elise Shanholtz Date: Mon, 28 Feb 2022 12:42:45 -0800 Subject: [PATCH 04/10] chore: push Datadog Release Metric upon deploy success (#1085) --- .github/workflows/test-and-deploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index c21ac557..dc365784 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -59,6 +59,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Submit metric to Datadog + uses: sendgrid/dx-automator/actions/datadog-release-metric@main + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + notify-on-failure: name: Slack notify on failure if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') From bb56501859da73af8f8b279ed7e6018ef1647eac Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Mar 2022 12:21:56 -0800 Subject: [PATCH 05/10] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ec51c0c..41c12025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +[2022-03-09] Version 7.11.5 +--------------------------- +**Library - Chore** +- [PR #1085](https://github.com/sendgrid/sendgrid-php/pull/1085): push Datadog Release Metric upon deploy success. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + + [2022-02-09] Version 7.11.4 --------------------------- **Library - Chore** From a1993e348142f276e1a9f9441bde9c5448e83806 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Mar 2022 12:21:56 -0800 Subject: [PATCH 06/10] Release 7.11.5 --- README.md | 4 ++-- lib/BaseSendGridClientInterface.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fa624dc1..506c97b1 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ Add Twilio SendGrid to your `composer.json` file. If you are not using [Composer ### Alternative: Install package from zip -If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.4/sendgrid-php.zip)**. +If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.5/sendgrid-php.zip)**. -[**⬇︎ Download Packaged Library ⬇︎**](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.4/sendgrid-php.zip) +[**⬇︎ Download Packaged Library ⬇︎**](https://github.com/sendgrid/sendgrid-php/releases/download/7.11.5/sendgrid-php.zip) Previous versions of the library can be downloaded directly from [GitHub](https://github.com/sendgrid/sendgrid-php/releases). diff --git a/lib/BaseSendGridClientInterface.php b/lib/BaseSendGridClientInterface.php index 846d38cc..a600a6eb 100644 --- a/lib/BaseSendGridClientInterface.php +++ b/lib/BaseSendGridClientInterface.php @@ -12,7 +12,7 @@ abstract class BaseSendGridClientInterface { /** @var string SendGrid API library version */ - const VERSION = '7.11.4'; + const VERSION = '7.11.5'; /** @var Client SendGrid HTTP Client library */ public $client; From ec3dc9e6b84813358318d9315ca7bb10990d540b Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Thu, 24 Mar 2022 10:48:12 -0500 Subject: [PATCH 07/10] chore: remove outdated announcements --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 506c97b1..2935ee5e 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ **NEW:** -**The default branch name for this repository has been changed to `main` as of 07/27/2020.** - - Send SMS messages with [Twilio](USE_CASES.md#sms). **This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via PHP.** From 376996784e198dacfdbd8e9a50e1639cc0f86a45 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Fri, 25 Mar 2022 13:39:51 -0500 Subject: [PATCH 08/10] feat: add PR title validation --- .github/workflows/pr-lint.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/pr-lint.yml diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 00000000..8388f21e --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,15 @@ +name: Lint PR +on: + pull_request_target: + types: [ opened, edited, reopened ] + +jobs: + validate: + name: Validate title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v4 + with: + types: chore docs fix feat test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From ace76617ad04b01c88723e7131b347de5ffc95d5 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Tue, 12 Apr 2022 15:01:12 -0500 Subject: [PATCH 09/10] drop support for EOL PHP versions and upgrade phpunit --- .github/workflows/test-and-deploy.yml | 2 +- CONTRIBUTING.md | 2 +- Makefile | 4 -- README.md | 2 +- UPGRADE.md | 8 +++ composer.json | 7 +-- test/BaseTestClass.php | 6 +-- test/integration/Helpers/Stats/StatsTest.php | 11 ++-- test/unit/AsmTest.php | 18 +++---- test/unit/BatchIdTest.php | 11 ++-- test/unit/BccSettingsTest.php | 25 +++++---- test/unit/BypassBounceManagementTest.php | 9 ++-- test/unit/BypassListManagementTest.php | 9 ++-- test/unit/BypassSpamManagementTest.php | 9 ++-- test/unit/BypassUnsubscribeManagementTest.php | 9 ++-- test/unit/CategoryTest.php | 11 ++-- test/unit/ClickTrackingTest.php | 16 +++--- test/unit/ContentTest.php | 20 +++---- test/unit/CustomArgTest.php | 20 +++---- test/unit/EmailAddressTest.php | 43 +++++++-------- test/unit/EventWebhookTest.php | 2 +- test/unit/FooterTest.php | 27 +++++----- test/unit/GanalyticsTest.php | 54 +++++++++---------- test/unit/GroupIdTest.php | 9 ++-- test/unit/GroupsToDisplayTest.php | 7 ++- test/unit/HeaderTest.php | 20 +++---- test/unit/IpPoolNameTest.php | 11 ++-- test/unit/OpenTrackingTest.php | 19 ++++--- test/unit/PersonalizationTest.php | 36 ++++++------- test/unit/SandBoxModeTest.php | 10 ++-- test/unit/SectionTest.php | 17 +++--- test/unit/SendAtTest.php | 10 ++-- test/unit/SpamCheckTest.php | 24 ++++----- test/unit/SubjectTest.php | 10 ++-- test/unit/SubscriptionTrackingTest.php | 31 +++++------ test/unit/SubstitutionTest.php | 18 +++---- test/unit/TemplateIdTest.php | 10 ++-- test/unit/TwilioEmailTest.php | 6 +-- 38 files changed, 278 insertions(+), 285 deletions(-) create mode 100644 UPGRADE.md diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index dc365784..626bb5a7 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', '8.0', '8.1' ] + php: [ '7.3', '7.4', '8.0', '8.1' ] env: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d5f9efbe..6e91f544 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 b7438ba8..3372c163 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* diff --git a/README.md b/README.md index 2935ee5e..07dfb3c2 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, 7.4, 8.0, or 8.1 +- 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 00000000..6de142ce --- /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 f9e25e34..047750f0 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 1b752ee0..0c1f2a6c 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 6f495d50..6fb9af31 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 ed83a7b0..93b7f4a2 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 0a7abe6f..ca89d6a6 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 a000bed1..55ef665c 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 9d28e4e3..ee7cfd35 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 00d44af5..77fb16c5 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 6160d621..ae9d432b 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 82da849c..19e86559 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 82df88c6..fc36c6c0 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 84f6e360..232f71b9 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 ece3be28..4eb29d1c 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 f7f3b58b..a2aae232 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 5e4ecbca..162d64e5 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 c84546ed..2ab098d2 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 c3d0d677..49615e06 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 367fc049..0c383603 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 16c54440..c5fb5cb3 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 010e5efb..9296295d 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 652746a2..5e91fae7 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 e224d8c2..94b05f17 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 2064c787..0ac46037 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 5aca0b8d..9bd35ba4 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 61f589e0..656f5dc9 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 503b8bec..d83bdb74 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 1ce9bd60..0366cafa 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 2d0efc33..e4d90009 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 ef0cb7c8..4c5bcbb4 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 9f354545..bc2aec63 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 668dfb9c..3bbfc678 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 0358eefb..33143c00 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 a9a03a83..d77803c4 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()); From c91a314e69fb22c5e87652941a0e8a007a4cb2be Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Tue, 12 Apr 2022 16:10:04 -0500 Subject: [PATCH 10/10] drop old travis exclusion --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3372c163..d482e48a 100644 --- a/Makefile +++ b/Makefile @@ -34,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\*