-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(postgresql): enforce public properties to fix postgreSQL serializ…
…ation
- Loading branch information
Showing
6 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Binarcode\LaravelMailator\Tests\Feature; | ||
|
||
use Binarcode\LaravelMailator\Models\MailatorSchedule; | ||
use Binarcode\LaravelMailator\Tests\Fixtures\PrivatePropertyMailable; | ||
use Binarcode\LaravelMailator\Tests\Fixtures\ProtectedPropertyMailable; | ||
use Binarcode\LaravelMailator\Tests\Fixtures\PublicPropertyMailable; | ||
use Binarcode\LaravelMailator\Tests\TestCase; | ||
use Illuminate\Support\Facades\Mail; | ||
use RuntimeException; | ||
|
||
class AllowNonPublicPropertiesTest extends TestCase | ||
{ | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Mail::fake(); | ||
} | ||
|
||
public function test_can_send_email_with_private_property(): void | ||
{ | ||
config()->set('mailator.serialization.enforce_public_properties', false); | ||
|
||
MailatorSchedule::init('private') | ||
->mailable(new PrivatePropertyMailable('test')) | ||
->execute(); | ||
|
||
Mail::assertSent(PrivatePropertyMailable::class); | ||
} | ||
|
||
public function test_can_not_send_email_with_private_property(): void | ||
{ | ||
config()->set('mailator.serialization.enforce_public_properties', true); | ||
|
||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Mailable contains non-public constructor properties which cannot be safely serialized'); | ||
|
||
MailatorSchedule::init('private') | ||
->mailable(new PrivatePropertyMailable('test')) | ||
->execute(); | ||
} | ||
|
||
public function test_can_send_email_with_protected_property(): void | ||
{ | ||
config()->set('mailator.serialization.enforce_public_properties', false); | ||
|
||
MailatorSchedule::init('protected') | ||
->mailable(new ProtectedPropertyMailable('test')) | ||
->execute(); | ||
|
||
Mail::assertSent(ProtectedPropertyMailable::class); | ||
} | ||
|
||
public function test_can_not_send_email_with_protected_property(): void | ||
{ | ||
config()->set('mailator.serialization.enforce_public_properties', true); | ||
|
||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Mailable contains non-public constructor properties which cannot be safely serialized'); | ||
|
||
MailatorSchedule::init('protected') | ||
->mailable(new ProtectedPropertyMailable('test')) | ||
->execute(); | ||
} | ||
|
||
public function test_can_send_email_with_public_property(): void | ||
{ | ||
config()->set('mailator.serialization.enforce_public_properties', true); | ||
|
||
MailatorSchedule::init('protected') | ||
->mailable(new PublicPropertyMailable('test')) | ||
->execute(); | ||
|
||
Mail::assertSent(PublicPropertyMailable::class); | ||
|
||
config()->set('mailator.serialization.enforce_public_properties', false); | ||
|
||
MailatorSchedule::init('protected') | ||
->mailable(new PublicPropertyMailable('test')) | ||
->execute(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
|
||
namespace Binarcode\LaravelMailator\Tests\Fixtures; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class PrivatePropertyMailable extends Mailable | ||
{ | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct( | ||
private string $name | ||
) { | ||
} | ||
|
||
public function build() | ||
{ | ||
return $this->view('laravel-mailator::mails.stub_invoice_reminder_view'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
|
||
namespace Binarcode\LaravelMailator\Tests\Fixtures; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProtectedPropertyMailable extends Mailable | ||
{ | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct( | ||
protected string $name | ||
) { | ||
} | ||
|
||
public function build() | ||
{ | ||
return $this->view('laravel-mailator::mails.stub_invoice_reminder_view'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
|
||
namespace Binarcode\LaravelMailator\Tests\Fixtures; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class PublicPropertyMailable extends Mailable | ||
{ | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct( | ||
public string $name | ||
) { | ||
} | ||
|
||
public function build() | ||
{ | ||
return $this->view('laravel-mailator::mails.stub_invoice_reminder_view'); | ||
} | ||
} |