Skip to content

Commit 66006da

Browse files
authored
Prevent creating pointless update jobs for up-to-date sites (#39)
1 parent 275049e commit 66006da

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/Jobs/CheckSiteHealth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function handle(): void
6969
}
7070

7171
// Available version is not newer, exit
72-
if (version_compare($latestVersion, $this->site->cms_version, "<")) {
72+
if (version_compare($latestVersion, $this->site->cms_version, "<=")) {
7373
return;
7474
}
7575

tests/Unit/Jobs/CheckSiteHealthTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\TUF\TufFetcher;
1111
use Illuminate\Support\Facades\App;
1212
use Illuminate\Support\Facades\Queue;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314
use Tests\TestCase;
1415

1516
class CheckSiteHealthTest extends TestCase
@@ -35,7 +36,8 @@ public function testCheckSiteHealthUpdatesDbRow()
3536
$object->handle();
3637
}
3738

38-
public function testCheckHealthTriggersUpdateJobIfNewerVersionIsAvailable()
39+
#[DataProvider('updateNecessityProvider')]
40+
public function testCheckHealthTriggersUpdateJobIfRequired($currentVersion, $doUpdate)
3941
{
4042
Queue::fake();
4143

@@ -50,14 +52,28 @@ public function testCheckHealthTriggersUpdateJobIfNewerVersionIsAvailable()
5052
->disableOriginalConstructor()
5153
->getMock();
5254

53-
$tufMock->method('getLatestVersionForBranch')->willReturn("2.0.0");
55+
$tufMock->method('getLatestVersionForBranch')->willReturn($currentVersion);
5456

5557
App::bind(TufFetcher::class, fn () => $tufMock);
5658

5759
$object = new CheckSiteHealth($siteMock);
5860
$object->handle();
5961

60-
Queue::assertPushed(UpdateSite::class);
62+
if ($doUpdate) {
63+
Queue::assertPushed(UpdateSite::class);
64+
} else {
65+
Queue::assertNotPushed(UpdateSite::class);
66+
}
67+
}
68+
69+
public static function updateNecessityProvider(): array
70+
{
71+
return [
72+
['0.9.1', false],
73+
['1.0.0', false],
74+
['1.0.1', true],
75+
['2.0.0', true]
76+
];
6177
}
6278

6379
protected function getSiteMock($healthMock)

0 commit comments

Comments
 (0)