Skip to content

Commit c26d83b

Browse files
author
Holger Lösken
committed
Improve testing
1 parent a18787c commit c26d83b

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed

config/self-update.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
| Exclude folders from update
6161
|--------------------------------------------------------------------------
6262
|
63-
| Specifiy folders which should not be updated and will be skipped during the
63+
| Specific folders which should not be updated and will be skipped during the
6464
| update process.
6565
|
6666
| Here's already a list of good examples to skip. You may want to keep those.
@@ -114,13 +114,13 @@
114114

115115
'mail' => [
116116
'to' => [
117-
'address' => env('SELF_UPDATER_MAILTO_ADDRESS', ''),
117+
'address' => env('SELF_UPDATER_MAILTO_ADDRESS', '[email protected]'),
118118
'name' => env('SELF_UPDATER_MAILTO_NAME', ''),
119119
],
120120

121121
'from' => [
122-
'address' => env('SELF_UPDATER_MAIL_FROM_ADDRESS', ''),
123-
'name' => env('SELF_UPDATER_MAIL_FROM_NAME', ''),
122+
'address' => env('SELF_UPDATER_MAIL_FROM_ADDRESS', '[email protected]'),
123+
'name' => env('SELF_UPDATER_MAIL_FROM_NAME', 'Update'),
124124
],
125125
]
126126
],

src/Events/UpdateSucceeded.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class UpdateSucceeded
88
{
9-
protected $release;
10-
119
/**
12-
* UpdateFailed constructor.
13-
*
14-
* @param Release $release
10+
* @var Release
1511
*/
12+
protected $release;
13+
1614
public function __construct(Release $release)
1715
{
1816
$this->release = $release;

src/Models/UpdateExecutor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function run(Release $release): bool
6666

6767
// Delete the version file
6868
$this->deleteVersionFile();
69+
6970
event(new UpdateSucceeded($release));
7071

7172
return true;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Codedge\Updater\Tests\Notifications;
4+
5+
6+
use Codedge\Updater\Events\UpdateFailed;
7+
use Codedge\Updater\Models\Release;
8+
use Codedge\Updater\Notifications\Notifiable;
9+
use Codedge\Updater\Notifications\Notifications\UpdateFailed as UpdateFailedNotification;
10+
use Codedge\Updater\Tests\TestCase;
11+
use Illuminate\Support\Facades\Notification;
12+
13+
class EventHandlerTest extends TestCase
14+
{
15+
public function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
Notification::fake();
20+
}
21+
22+
/** @test */
23+
public function it_will_send_a_notification_by_default_when_update_failed()
24+
{
25+
$this->fireUpdateFailedEvent();
26+
27+
Notification::assertSentTo(new Notifiable(), UpdateFailedNotification::class);
28+
}
29+
30+
/**
31+
* @test
32+
*
33+
* @dataProvider channelProvider
34+
*
35+
* @param array $expectedChannels
36+
*/
37+
public function it_will_send_a_notification_via_the_configured_notification_channels(array $expectedChannels)
38+
{
39+
config()->set('self-update.notifications.notifications.'.UpdateFailedNotification::class, $expectedChannels);
40+
41+
$this->fireUpdateFailedEvent();
42+
43+
Notification::assertSentTo(new Notifiable(), UpdateFailedNotification::class, function ($notification, $usedChannels) use ($expectedChannels) {
44+
return $expectedChannels == $usedChannels;
45+
});
46+
}
47+
48+
public function channelProvider()
49+
{
50+
return [
51+
[[]],
52+
[['mail']],
53+
];
54+
}
55+
56+
protected function fireUpdateFailedEvent()
57+
{
58+
$release = resolve(Release::class);
59+
60+
event(new UpdateFailed($release));
61+
}
62+
63+
}

0 commit comments

Comments
 (0)