Skip to content

Feature/enable build #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
30 changes: 24 additions & 6 deletions .github/workflows/quality-assurance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,43 @@ 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
testbench: ^6.6
- 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
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"notifications",
"laravel-7-package",
"laravel-8-package",
"laravel-9-package"
"laravel-9-package",
"laravel-10-package"
],
"type": "library",
"license": "MIT",
Expand All @@ -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": {
Expand All @@ -48,7 +49,7 @@
"extra": {
"laravel": {
"providers": [
"Craftzing\\Laravel\\NotificationChannels\\NotificationChannels\\ServiceProvider"
"Craftzing\\Laravel\\NotificationChannels\\Postmark\\ServiceProvider"
]
}
}
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(TemplatesApi $templatesApi)

/**
* {@inheritdoc}
* @param mixed $other
*/
public function matches($other): bool
{
Expand Down Expand Up @@ -83,6 +84,7 @@ private function postmarkTemplateMessage($other): TemplateMessage

/**
* {@inheritdoc}
* @param mixed $other
*/
protected function failureDescription($other): string
{
Expand Down
13 changes: 9 additions & 4 deletions src/RenderedEmailTemplateMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
41 changes: 41 additions & 0 deletions src/RenderedEmailTemplateMailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Craftzing\Laravel\NotificationChannels\Postmark;

use PHPUnit\Framework\TestCase;

final class RenderedEmailTemplateMailTest extends TestCase
{
/** @test */
public function itCanBeConstructedFromRenderedContent(): void
{
$subject = 'Some Content Here';
$htmlBody = 'Some HTML Content Here';
$textBody = 'Some Text Content Here';

$mail = RenderedEmailTemplateMail::fromRenderedContent($subject, $htmlBody, $textBody);

$this->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);
}
}
4 changes: 4 additions & 0 deletions src/SdkTemplatesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public function validate(TemplateMessage $message): ValidatedTemplateMessage
}

/**
* @param DynamicResponseModel<mixed> $template
* @param array<mixed> $model
* @param bool $inlineCss
*
* @return DynamicResponseModel<mixed>
*/
private function validateTemplate(
DynamicResponseModel $template,
Expand Down
22 changes: 22 additions & 0 deletions src/ValidatedTemplateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ final class ValidatedTemplateMessage
*/
public array $invalidVariables = [];

/**
* @var DynamicResponseModel<mixed>
*/
private DynamicResponseModel $renderedTemplate;

/**
* @param DynamicResponseModel<mixed> $renderedTemplate
* @param DynamicResponseModel<mixed> $model
* @param DynamicResponseModel<mixed> $suggestedModel
*/
private function __construct(
DynamicResponseModel $renderedTemplate,
DynamicResponseModel $model,
Expand All @@ -60,6 +68,13 @@ private function __construct(
$this->parseForValidationErrors($model, $suggestedModel);
}

/**
* @param DynamicResponseModel<mixed> $renderedTemplate
* @param TemplateModel $model
* @param DynamicResponseModel<mixed> $suggestedModel
*
* @return self
*/
public static function validate(
DynamicResponseModel $renderedTemplate,
TemplateModel $model,
Expand All @@ -71,6 +86,10 @@ public static function validate(
return new self($renderedTemplate, new DynamicResponseModel($model->variables()), $suggestedModel);
}

/**
* @param DynamicResponseModel<mixed> $model
* @param DynamicResponseModel<mixed> $suggestedModel
*/
private function parseForValidationErrors(DynamicResponseModel $model, DynamicResponseModel $suggestedModel): void
{
foreach ($suggestedModel as $key => $suggestedValue) {
Expand All @@ -92,7 +111,10 @@ private function parseForValidationErrors(DynamicResponseModel $model, DynamicRe

/**
* @param string|int $key
* @param DynamicResponseModel<mixed> $model
* @param string|array<mixed> $suggestedValue
*
* @return bool
*/
private function isMarkedAsMissing($key, DynamicResponseModel $model, $suggestedValue): bool
{
Expand Down