Skip to content

Commit f1dc830

Browse files
committed
test: improve tests to check notifiable that inherits Eloquent model (as more usable case)
refs: #269
1 parent 6dc1e78 commit f1dc830

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

tests/NotificationsMockTraitTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testAssertNotificationsSentToMultipleNotifiables(): void
4747
);
4848

4949
Notification::send(
50-
new TestNotifiable(2),
50+
new TestNotifiable(['id' => 2]),
5151
new TestNotification(
5252
firstParam: 'value-3',
5353
secondParam: 'value-4',
@@ -58,6 +58,13 @@ public function testAssertNotificationsSentToMultipleNotifiables(): void
5858
$this->assertNotificationsSent('assert_notifications_sent_to_multiple_notifiables');
5959
}
6060

61+
public function testAssertNotificationsSentWithAnonymousNotifiable(): void
62+
{
63+
Notification::route('mail', 'test@example.com')->notify(new TestNotification());
64+
65+
$this->assertNotificationsSent('assert_notifications_sent_with_anonymous_notifiable');
66+
}
67+
6168
public function testAssertMultipleNotificationTypesSent(): void
6269
{
6370
Notification::send(new TestNotifiable(), new TestNotification());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"RonasIT\\Support\\Tests\\Support\\Mock\\Notifications\\TestNotification": [
3+
{
4+
"notification": {
5+
"firstParam": "value-1",
6+
"secondParam": "value-2",
7+
"thirdParam": 1,
8+
"channels": [
9+
"database"
10+
],
11+
"locale": null
12+
},
13+
"channels": [
14+
"database"
15+
],
16+
"notifiable": {
17+
"routes": {
18+
"mail": "test@example.com"
19+
}
20+
},
21+
"locale": null
22+
}
23+
]
24+
}

tests/support/Mock/Models/TestNotifiable.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
namespace RonasIT\Support\Tests\Support\Mock\Models;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Notifications\Notifiable;
67

7-
class TestNotifiable
8+
class TestNotifiable extends Model
89
{
910
use Notifiable;
1011

11-
public function __construct(
12-
public int $id = 1,
13-
) {
14-
}
12+
protected $fillable = [
13+
'id',
14+
'name',
15+
];
1516

16-
public function getKey(): int
17-
{
18-
return $this->id;
19-
}
17+
protected $attributes = [
18+
'id' => 1,
19+
'name' => 'John Doe',
20+
];
2021
}

0 commit comments

Comments
 (0)