Skip to content

Commit 72aa806

Browse files
committed
wip
1 parent 5844f79 commit 72aa806

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</testsuite>
1616
</testsuites>
1717
<php>
18-
<env name="QUEUE_DRIVER" value="9000"/>
18+
<env name="QUEUE_CONNECTION" value="database"/>
1919
</php>
2020
<filter>
2121
<whitelist>

src/CallWebhookJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function handle()
8181
$waitInSeconds = $backoffStrategy->waitInSecondsAfterAttempt($this->attempts());
8282

8383
$this->dispatchEvent(WebhookCallFailedEvent::class);
84+
8485
$this->release($waitInSeconds);
8586
}
8687

tests/CallWebhookJobTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use GuzzleHttp\Client;
66
use Illuminate\Support\Facades\Event;
7+
use Spatie\WebhookServer\Events\FinalWebhookCallFailedEvent;
8+
use Spatie\WebhookServer\Events\WebhookCallFailedEvent;
79
use Spatie\WebhookServer\Tests\TestClasses\TestClient;
810
use Spatie\WebhookServer\Webhook;
911

@@ -30,6 +32,8 @@ public function it_can_make_a_webhook_call()
3032
{
3133
$this->baseWebhook()->call();
3234

35+
$this->artisan('queue:work --once');
36+
3337
$this
3438
->testClient
3539
->assertRequestsMade([$this->baseRequest()]);
@@ -45,6 +49,9 @@ public function it_can_use_a_different_http_verb()
4549

4650
$baseResponse = $this->baseRequest(['method' => 'get']);
4751

52+
$this->artisan('queue:work --once');
53+
54+
4855
$this
4956
->testClient
5057
->assertRequestsMade([$baseResponse]);
@@ -69,6 +76,8 @@ public function it_can_add_extra_headers()
6976
$extraHeaders,
7077
);
7178

79+
$this->artisan('queue:work --once');
80+
7281
$this
7382
->testClient
7483
->assertRequestsMade([$baseRequest]);
@@ -82,18 +91,37 @@ public function it_can_disable_verifying_ssl()
8291
$baseRequest = $this->baseRequest();
8392
$baseRequest['options']['verify'] = false;
8493

94+
$this->artisan('queue:work --once');
95+
8596
$this
8697
->testClient
8798
->assertRequestsMade([$baseRequest]);
8899
}
89100

90101
/** @test */
91-
public function it_will_try_the_amount_of_times()
102+
public function by_default_it_will_retry_3_times_with_the_exponential_backoff_strategy()
92103
{
93104
$this->testClient->letEveryRequestFail();
94105

95106
$this->baseWebhook()->call();
96107

108+
$this->artisan('queue:work --once');
109+
Event::assertDispatched(WebhookCallFailedEvent::class, 1);
110+
111+
$this->progressSeconds(10);
112+
$this->artisan('queue:work --once');
113+
Event::assertDispatched(WebhookCallFailedEvent::class, 2);
114+
115+
$this->progressSeconds(100);
116+
$this->artisan('queue:work --once');
117+
Event::assertDispatched(WebhookCallFailedEvent::class, 3);
118+
Event::assertDispatched(FinalWebhookCallFailedEvent::class, 1);
119+
$this->testClient->assertRequestCount(3);
120+
121+
$this->progressSeconds(1000);
122+
$this->artisan('queue:work --once');
123+
Event::assertDispatched(WebhookCallFailedEvent::class, 3);
124+
Event::assertDispatched(FinalWebhookCallFailedEvent::class, 1);
97125
$this->testClient->assertRequestCount(3);
98126
}
99127

tests/TestCase.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spatie\WebhookServer\Tests;
44

5+
use Carbon\Carbon;
56
use Illuminate\Database\Schema\Blueprint;
67
use Illuminate\Support\Facades\Schema;
78
use Orchestra\Testbench\TestCase as Orchestra;
@@ -25,7 +26,6 @@ protected function getPackageProviders($app)
2526

2627
protected function getEnvironmentSetUp($app)
2728
{
28-
// Setup default database to use sqlite :memory:
2929
$app['config']->set('database.default', 'testbench');
3030
$app['config']->set('database.connections.testbench', [
3131
'driver' => 'sqlite',
@@ -46,5 +46,18 @@ protected function setUpDatabase()
4646
$table->unsignedInteger('created_at');
4747
});
4848
}
49-
}
5049

50+
protected function setNow(string $time, $format = 'Y-m-d H:i:s')
51+
{
52+
$now = Carbon::createFromFormat($format, $time);
53+
54+
Carbon::setTestNow($now);
55+
}
56+
57+
public function progressSeconds(int $seconds)
58+
{
59+
$newNow = now()->addSeconds($seconds);
60+
61+
Carbon::setTestNow($newNow);
62+
}
63+
}

0 commit comments

Comments
 (0)