Skip to content

Commit 7d6e030

Browse files
authored
Merge pull request #5 from BinarCode/helper
slack helper.
2 parents 430d892 + 5098c14 commit 7d6e030

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/helpers.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Binarcode\LaravelDeveloper\LaravelDeveloper;
34
use Binarcode\LaravelDeveloper\Profiling\ServerMemory;
45
use Binarcode\LaravelDeveloper\Profiling\ServerTiming;
56

@@ -38,3 +39,22 @@ function measure_timing($callable = null, string $key = 'action')
3839
return dd($timing->getDuration($key));
3940
}
4041
}
42+
43+
if (! function_exists('slack')) {
44+
function slack(...$args)
45+
{
46+
$instance = new LaravelDeveloper;
47+
48+
collect($args)->each(function ($item) use ($instance) {
49+
if (is_string($item)) {
50+
$instance::messageToDevSlack($item);
51+
}
52+
53+
if ($item instanceof Throwable) {
54+
$instance::exceptionToDevSlack($item);
55+
}
56+
});
57+
58+
return $instance;
59+
}
60+
}

tests/Helpers/SlackHelperTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelDeveloper\Tests\Helpers;
4+
5+
use Binarcode\LaravelDeveloper\LaravelDeveloper;
6+
use Binarcode\LaravelDeveloper\Notifications\DevNotification;
7+
use Binarcode\LaravelDeveloper\Tests\TestCase;
8+
use Exception;
9+
use Illuminate\Notifications\AnonymousNotifiable;
10+
use Illuminate\Support\Facades\Notification;
11+
12+
class SlackHelperTest extends TestCase
13+
{
14+
public function test_slack_helper_returns_laravel_developer_instance()
15+
{
16+
$this->assertInstanceOf(LaravelDeveloper::class, slack());
17+
$this->assertInstanceOf(LaravelDeveloper::class, slack('message'));
18+
$this->assertInstanceOf(LaravelDeveloper::class, slack(new Exception()));
19+
}
20+
21+
public function test_slack_helper_can_send_message_to_slack()
22+
{
23+
Notification::fake();
24+
25+
$this->assertInstanceOf(LaravelDeveloper::class, slack('message'));
26+
27+
Notification::assertSentTo(new AnonymousNotifiable, DevNotification::class);
28+
}
29+
30+
public function test_slack_helper_can_send_throwable_to_slack()
31+
{
32+
Notification::fake();
33+
34+
$this->assertInstanceOf(LaravelDeveloper::class, slack(new Exception()));
35+
36+
Notification::assertSentTo(new AnonymousNotifiable, DevNotification::class);
37+
}
38+
}

0 commit comments

Comments
 (0)