Skip to content

Commit 28c7c01

Browse files
committed
fix tests
1 parent b10cb01 commit 28c7c01

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

app/Jobs/UpdateSite.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public function handle(): void
7676
protected function performExtraction(PrepareUpdate $prepareResult): void
7777
{
7878
/** Create a separate connection with the extraction password **/
79-
$connection = App::make(Connection::class, [
80-
$this->site->url,
81-
$prepareResult->password
79+
$connection = App::makeWith(Connection::class, [
80+
"baseUrl" => $this->site->url,
81+
"key" => $prepareResult->password
8282
]);
8383

8484
// Ping server

tests/Unit/Jobs/UpdateSiteTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\RemoteSite\Responses\GetUpdate;
1010
use App\RemoteSite\Responses\HealthCheck;
1111
use App\RemoteSite\Responses\PrepareUpdate;
12+
use Illuminate\Support\Facades\App;
1213
use Illuminate\Support\Facades\Log;
1314
use Tests\TestCase;
1415

@@ -91,6 +92,8 @@ public function testJobFailsIfFinalizeUpdateReturnsFalse()
9192
]
9293
);
9394

95+
App::bind(Connection::class, fn() => $this->getSuccessfulExtractionMock());
96+
9497
$object = new UpdateSite($site, "1.0.1");
9598
$object->handle();
9699
}
@@ -163,4 +166,30 @@ protected function getPrepareUpdateMock($overrides = [])
163166
...$overrides
164167
]);
165168
}
169+
170+
protected function getSuccessfulExtractionMock()
171+
{
172+
$connectionMock = $this->getMockBuilder(Connection::class)
173+
->disableOriginalConstructor()
174+
->getMock();
175+
176+
$connectionMock
177+
->method("performExtractionRequest")
178+
->willReturnCallback(
179+
function ($data) {
180+
switch ($data["task"]) {
181+
case "ping":
182+
return ["message" => "Success"];
183+
184+
case "startExtract":
185+
return ["done" => true];
186+
187+
case "finalizeUpdate":
188+
return ["success" => true];
189+
}
190+
}
191+
);
192+
193+
return $connectionMock;
194+
}
166195
}

0 commit comments

Comments
 (0)