Skip to content

Commit c72d2a4

Browse files
committed
fix: config to enable slack
1 parent 38569ef commit c72d2a4

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

config/developer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
'model' => \Binarcode\LaravelDeveloper\Models\DeveloperLog::class,
1313

1414
/**
15-
* The slack incoming webhook to send notifications.
15+
* Indicate whether to allow using slack helper.
16+
*/
17+
'slack_dev_enabled' => env('SLACK_DEV_LOG_ENABLED', true),
18+
19+
/**
20+
* The slack webhook to send notifications.
1621
*/
1722
'slack_dev_hook' => env('SLACK_DEV_HOOK'),
1823

src/Notifications/Slack.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ public function channel(string $channel): self
5757
return $this;
5858
}
5959

60-
private function send($item)
60+
private function send($item): self
6161
{
62+
if (! config('developer.slack_dev_enabled')) {
63+
return $this;
64+
}
65+
6266
/**
6367
* @var string $class
6468
*/

src/helpers.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ function measure_timing($callable = null, string $key = 'action')
4747
if (! function_exists('slack')) {
4848
function slack(...$args)
4949
{
50-
if (! App::runningUnitTests()) {
51-
return Slack::make($args);
52-
}
53-
54-
return false;
50+
return Slack::make($args);
5551
}
5652
}
5753

tests/Helpers/SlackHelperTest.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Binarcode\LaravelDeveloper\Tests\TestCase;
1010
use Exception;
1111
use Illuminate\Notifications\AnonymousNotifiable;
12-
use Illuminate\Support\Facades\App;
1312
use Illuminate\Support\Facades\Notification;
1413

1514
class SlackHelperTest extends TestCase
@@ -18,10 +17,6 @@ public function test_slack_helper_returns_laravel_developer_instance(): void
1817
{
1918
Notification::fake();
2019

21-
App::partialMock()
22-
->shouldReceive('environment')
23-
->andReturn('dev');
24-
2520
$this->assertInstanceOf(Slack::class, slack());
2621
$this->assertInstanceOf(Slack::class, slack('message'));
2722
$this->assertInstanceOf(Slack::class, slack(new Exception()));
@@ -31,10 +26,6 @@ public function test_slack_helper_can_send_message_to_slack(): void
3126
{
3227
Notification::fake();
3328

34-
App::partialMock()
35-
->shouldReceive('environment')
36-
->andReturn('dev');
37-
3829
$this->assertInstanceOf(Slack::class, slack('message'));
3930

4031
Notification::assertSentTo(new AnonymousNotifiable(), DevNotification::class);
@@ -48,10 +39,6 @@ public function test_slack_helper_can_send_throwable_to_slack(): void
4839
'developer.developer_log_base_url' => 'app.test/{id}',
4940
]);
5041

51-
App::partialMock()
52-
->shouldReceive('environment')
53-
->andReturn('dev');
54-
5542
$this->assertInstanceOf(Slack::class, slack(new Exception('not found', 404))->persist());
5643

5744
$this->assertDatabaseCount('developer_logs', 1);
@@ -67,25 +54,21 @@ public function test_slack_helper_can_send_throwable_to_slack(): void
6754
DevNotification::class,
6855
function (DevNotification $class) use ($uuid) {
6956
return $class->notificationDto->attachment_link === "app.test/{$uuid}";
70-
}
57+
},
7158
);
7259
}
7360

7461
public function test_slack_helper_can_send_notifications_to_slack(): void
7562
{
7663
Notification::fake();
7764

78-
App::partialMock()
79-
->shouldReceive('environment')
80-
->andReturn('dev');
81-
8265
config([
8366
'developer.developer_log_base_url' => 'app.test/{id}',
8467
'developer.slack_dev_hook' => 'https://test.com',
8568
]);
8669

8770
$this->assertInstanceOf(Slack::class, slack(
88-
new DummyNotification()
71+
new DummyNotification(),
8972
)->persist());
9073

9174
Notification::assertSentTo(new AnonymousNotifiable(), DummyNotification::class);

0 commit comments

Comments
 (0)