generated from Soyhuce/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pre-filled unit test for notifications
- Loading branch information
Showing
8 changed files
with
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* @@covers \{{ $covered }} */ | ||
|
||
use {{ $classFqcn }}; | ||
|
||
it('formats the mail', function (): void { | ||
$notification = new {{ $classBasename }}(); | ||
|
||
$this->assertEquals(['mail'], $notification->via()); | ||
|
||
$mail = $notification->toMail(); | ||
|
||
$this->assertEquals('', $mail->subject); | ||
$this->assertEquals('', $mail->greeting); | ||
$this->assertEquals([''], $mail->introLines); | ||
$this->assertEquals('', $mail->actionText); | ||
$this->assertEquals('', $mail->actionUrl); | ||
$this->assertEquals([''], $mail->outroLines); | ||
$this->assertEquals('', $mail->salutation); | ||
}); |
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
38 changes: 38 additions & 0 deletions
38
src/Domains/Test/UnitTestGenerators/NotificationTestGenerator.php
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,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soyhuce\Somake\Domains\Test\UnitTestGenerators; | ||
|
||
use Illuminate\Support\Str; | ||
use ReflectionClass; | ||
use Soyhuce\Somake\Contracts\UnitTestGenerator; | ||
|
||
/** | ||
* @implements \Soyhuce\Somake\Contracts\UnitTestGenerator<mixed> | ||
*/ | ||
class NotificationTestGenerator implements UnitTestGenerator | ||
{ | ||
public static function shouldHandle(string $class): bool | ||
{ | ||
if (!class_exists($class)) { | ||
return false; | ||
} | ||
|
||
if (!Str::is('Domain\\*\\Notifications\\*', $class)) { | ||
return false; | ||
} | ||
|
||
$reflectionClass = new ReflectionClass($class); | ||
|
||
return $reflectionClass->hasMethod('toMail'); | ||
} | ||
|
||
public function view(): string | ||
{ | ||
return 'test-unit-notification'; | ||
} | ||
|
||
public function data(string $class): array | ||
{ | ||
return []; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test-laravel/app/Domain/User/Notifications/AccountCreatedNotification.php
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,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Domain\User\Notifications; | ||
|
||
use Domain\User\Models\User; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Support\Facades\Lang; | ||
|
||
class AccountCreatedNotification extends Notification | ||
{ | ||
/** | ||
* @return array<string>|string | ||
*/ | ||
public function via(): array|string | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
public function toMail(User $user): MailMessage | ||
{ | ||
return (new MailMessage()) | ||
->greeting(Lang::get('Hello :name,', ['name' => $user->name])) | ||
->subject(Lang::get('Your account has been created')) | ||
->line(Lang::get('Your account has been created, you can now connect to the platform using your usual credentials.')) | ||
->action(Lang::get('Connect'), url('/')); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...shots__/files/TestCommandTest__it_creates_correctly_the_unit_test_for_notification__1.php
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,21 @@ | ||
<?php | ||
|
||
/* @covers \Domain\User\Notifications\AccountCreatedNotification */ | ||
|
||
use Domain\User\Notifications\AccountCreatedNotification; | ||
|
||
it('formats the mail', function (): void { | ||
$notification = new AccountCreatedNotification(); | ||
|
||
$this->assertEquals(['mail'], $notification->via()); | ||
|
||
$mail = $notification->toMail(); | ||
|
||
$this->assertEquals('', $mail->subject); | ||
$this->assertEquals('', $mail->greeting); | ||
$this->assertEquals([''], $mail->introLines); | ||
$this->assertEquals('', $mail->actionText); | ||
$this->assertEquals('', $mail->actionUrl); | ||
$this->assertEquals([''], $mail->outroLines); | ||
$this->assertEquals('', $mail->salutation); | ||
}); |