Skip to content

Commit 8719494

Browse files
committed
slack helper.
1 parent 430d892 commit 8719494

File tree

2 files changed

+61
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)