diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index 47cb58f..3d91139 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index ad8934c..dc7bb0e 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -9,10 +9,12 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.0.2, 8.0, 7.4] - laravel: [^8.0, ^7.0, ^9.0] + php: [8.2, 8.1, 8.0.2, 8.0, 7.4] + laravel: [^8.0, ^7.0, ^9.0, ^10.0] dependency-version: [prefer-lowest, prefer-stable] include: + - laravel: ^10.0 + testbench: ^8.0 - laravel: ^9.0 testbench: ^7.0 - laravel: ^8.0 @@ -20,14 +22,30 @@ jobs: - laravel: ^7.0 testbench: ^5.20 exclude: + - laravel: ^7.0 + php: 8.1 + - laravel: ^7.0 + php: 8.2 + - laravel: ^8.0 + php: 8.1 + - laravel: ^8.0 + php: 8.2 - laravel: ^9.0 php: 7.4 - laravel: ^9.0 php: 8.0 + - laravel: ^9.0 + php: 8.0.2 + - laravel: ^10.0 + php: 7.4 + - laravel: ^10.0 + php: 8.0 + - laravel: ^10.0 + php: 8.0.2 name: PHP ${{ matrix.php }} with Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }} steps: - name: "Checkout code" - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: "Setup PHP" uses: shivammathur/setup-php@v2 @@ -47,14 +65,14 @@ jobs: echo "POSTMARK_TOKEN=${{ secrets.POSTMARK_TOKEN }}" > .env - name: "Run tests" - run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover + run: vendor/bin/phpunit --coverage-clover=coverage.clover - name: "Run tests & publish code coverage" - uses: paambaati/codeclimate-action@v2.7.5 + uses: paambaati/codeclimate-action@v3.2.0 env: CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }} with: - coverageCommand: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover + coverageCommand: vendor/bin/phpunit --coverage-clover=coverage.clover coverageLocations: | ${{github.workspace}}/*.clover:clover debug: true diff --git a/composer.json b/composer.json index 203dcea..170c412 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "notifications", "laravel-7-package", "laravel-8-package", - "laravel-9-package" + "laravel-9-package", + "laravel-10-package" ], "type": "library", "license": "MIT", @@ -25,15 +26,15 @@ "php": "^7.4|^8.0", "ext-json": "*", "guzzlehttp/guzzle": "^6.3|^7.0", - "illuminate/support": "^7.0|^8.0|^9.0", + "illuminate/support": "^7.0|^8.0|^9.0|^10.0", "myclabs/php-enum": "^1.8", "wildbit/postmark-php": "^4.0" }, "require-dev": { "fakerphp/faker": "^1.17", - "orchestra/testbench": "^5.20|^6.6|^7.0", + "orchestra/testbench": "^5.20|^6.6|^7.0|^8.0", "phpstan/phpstan": "^1.4", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5|^10" }, "autoload": { "psr-4": { @@ -48,7 +49,7 @@ "extra": { "laravel": { "providers": [ - "Craftzing\\Laravel\\NotificationChannels\\NotificationChannels\\ServiceProvider" + "Craftzing\\Laravel\\NotificationChannels\\Postmark\\ServiceProvider" ] } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1e7016d..d42daec 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,8 +7,4 @@ parameters: - ./**/*Test.php - ./**/*TestCase.php - ./**/Fake*.php - ignoreErrors: - - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) has parameter \$[a-zA-Z0-9]+ with no value type specified in iterable type Postmark\\Models\\DynamicResponseModel.#' - - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) return type has no value type specified in iterable type Postmark\\Models\\DynamicResponseModel.#' - - '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ type has no value type specified in iterable type Postmark\\Models\\DynamicResponseModel.#' checkGenericClassInNonGenericObjectType: false diff --git a/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApi.php b/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApi.php index ce12ab9..79fe8c5 100644 --- a/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApi.php +++ b/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApi.php @@ -11,6 +11,6 @@ trait InteractsWithPostmarkTemplatesApi { private function assertNotificationIsSendableAsPostmarkTemplate(Notification $notification): void { - $this->assertThat($notification, $this->app[IsSendableAsPostmarkTemplate::class]); + $this->assertThatPostmark($notification, $this->app[IsSendableAsPostmarkTemplate::class]); } } diff --git a/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApiTest.php b/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApiTest.php index e4dacbe..6fed511 100644 --- a/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApiTest.php +++ b/src/Extensions/Laravel/Testing/InteractsWithPostmarkTemplatesApiTest.php @@ -20,7 +20,7 @@ final class InteractsWithPostmarkTemplatesApiTest extends IntegrationTestCase /** * {@inheritdoc} */ - public static function assertThat($value, Constraint $constraint, string $message = ''): void + public static function assertThatPostmark($value, Constraint $constraint, string $message = ''): void { // Note that should overwrite this method in order to spy on the parameters it receives when calling // the `assertNotificationIsSendableAsPostmarkTemplate()` method of the trait we're testing... diff --git a/src/Extensions/PhpUnit/Constraints/IsSendableAsPostmarkTemplate.php b/src/Extensions/PhpUnit/Constraints/IsSendableAsPostmarkTemplate.php index 8ada254..370aee9 100644 --- a/src/Extensions/PhpUnit/Constraints/IsSendableAsPostmarkTemplate.php +++ b/src/Extensions/PhpUnit/Constraints/IsSendableAsPostmarkTemplate.php @@ -26,6 +26,7 @@ public function __construct(TemplatesApi $templatesApi) /** * {@inheritdoc} + * @param mixed $other */ public function matches($other): bool { @@ -83,6 +84,7 @@ private function postmarkTemplateMessage($other): TemplateMessage /** * {@inheritdoc} + * @param mixed $other */ protected function failureDescription($other): string { diff --git a/src/RenderedEmailTemplateMail.php b/src/RenderedEmailTemplateMail.php index d0f926c..5a8f64b 100644 --- a/src/RenderedEmailTemplateMail.php +++ b/src/RenderedEmailTemplateMail.php @@ -16,8 +16,13 @@ public static function fromRenderedContent(string $subject, string $html, string ->text($text); } -// public function build(): self -// { -// return $this; -// } + public function build(): self + { + return $this; + } + + public function htmlBody(): string + { + return $this->html; + } } diff --git a/src/RenderedEmailTemplateMailTest.php b/src/RenderedEmailTemplateMailTest.php new file mode 100644 index 0000000..e32a1b4 --- /dev/null +++ b/src/RenderedEmailTemplateMailTest.php @@ -0,0 +1,41 @@ +assertSame($subject, $mail->subject); + $this->assertSame($htmlBody, $mail->htmlBody()); + $this->assertSame($textBody, $mail->textView); + } + + /** @test */ + public function itCanBuildRenderdEmailTemplate(): void + { + $subject = 'Some Content Here'; + $htmlBody = 'Some HTML Content Here'; + $textBody = 'Some Text Content Here'; + $mail = RenderedEmailTemplateMail::fromRenderedContent($subject, $htmlBody, $textBody); + + // Laravel needs the build method on the mailable but doesn't use it when faking Mail. + // For that reason we test it here since it isn't picked up in any other test case. + $build = $mail->build(); + + $this->assertSame($subject, $build->subject); + $this->assertSame($htmlBody, $build->htmlBody()); + $this->assertSame($textBody, $build->textView); + } +} diff --git a/src/SdkTemplatesApi.php b/src/SdkTemplatesApi.php index 2554f74..0b69882 100644 --- a/src/SdkTemplatesApi.php +++ b/src/SdkTemplatesApi.php @@ -73,7 +73,11 @@ public function validate(TemplateMessage $message): ValidatedTemplateMessage } /** + * @param DynamicResponseModel $template * @param array $model + * @param bool $inlineCss + * + * @return DynamicResponseModel */ private function validateTemplate( DynamicResponseModel $template, diff --git a/src/ValidatedTemplateMessage.php b/src/ValidatedTemplateMessage.php index 6208016..da4aa95 100644 --- a/src/ValidatedTemplateMessage.php +++ b/src/ValidatedTemplateMessage.php @@ -45,8 +45,16 @@ final class ValidatedTemplateMessage */ public array $invalidVariables = []; + /** + * @var DynamicResponseModel + */ private DynamicResponseModel $renderedTemplate; + /** + * @param DynamicResponseModel $renderedTemplate + * @param DynamicResponseModel $model + * @param DynamicResponseModel $suggestedModel + */ private function __construct( DynamicResponseModel $renderedTemplate, DynamicResponseModel $model, @@ -60,6 +68,13 @@ private function __construct( $this->parseForValidationErrors($model, $suggestedModel); } + /** + * @param DynamicResponseModel $renderedTemplate + * @param TemplateModel $model + * @param DynamicResponseModel $suggestedModel + * + * @return self + */ public static function validate( DynamicResponseModel $renderedTemplate, TemplateModel $model, @@ -71,6 +86,10 @@ public static function validate( return new self($renderedTemplate, new DynamicResponseModel($model->variables()), $suggestedModel); } + /** + * @param DynamicResponseModel $model + * @param DynamicResponseModel $suggestedModel + */ private function parseForValidationErrors(DynamicResponseModel $model, DynamicResponseModel $suggestedModel): void { foreach ($suggestedModel as $key => $suggestedValue) { @@ -92,7 +111,10 @@ private function parseForValidationErrors(DynamicResponseModel $model, DynamicRe /** * @param string|int $key + * @param DynamicResponseModel $model * @param string|array $suggestedValue + * + * @return bool */ private function isMarkedAsMissing($key, DynamicResponseModel $model, $suggestedValue): bool {