From 084523d9fe01ad98b176f207d729813113215afd Mon Sep 17 00:00:00 2001 From: freekmurze Date: Tue, 23 Jan 2024 12:40:56 +0000 Subject: [PATCH] Fix styling --- src/Checks/Checks/BackupsCheck.php | 18 +++++++----------- tests/Checks/BackupsCheckTest.php | 22 ++++++++++------------ tests/Checks/DatabaseCheckTest.php | 1 - tests/Pest.php | 2 +- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/Checks/Checks/BackupsCheck.php b/src/Checks/Checks/BackupsCheck.php index 4db63d1d..02d6219f 100644 --- a/src/Checks/Checks/BackupsCheck.php +++ b/src/Checks/Checks/BackupsCheck.php @@ -14,6 +14,7 @@ class BackupsCheck extends Check protected ?string $locatedAt = null; protected ?Carbon $youngestShouldHaveBeenMadeBefore = null; + protected ?Carbon $oldestShouldHaveBeenMadeAfter = null; protected int $minimumSizeInMegabytes = 0; @@ -82,31 +83,28 @@ public function run(): Result if ($this->youngestShouldHaveBeenMadeBefore) { if ($this->youngestBackupIsToolOld($eligableBackups)) { return Result::make() - ->failed("Youngest backup was too old"); + ->failed('Youngest backup was too old'); } } if ($this->oldestShouldHaveBeenMadeAfter) { if ($this->oldestBackupIsTooYoung($eligableBackups)) { return Result::make() - ->failed("Oldest backup was too young"); + ->failed('Oldest backup was too young'); } } return Result::make()->ok(); } - /** - * @param Collection $backups - * - * @return bool + * @param Collection $backups */ protected function youngestBackupIsToolOld(Collection $backups): bool { /** @var SymfonyFile|null $youngestBackup */ $youngestBackup = $backups - ->sortByDesc(fn(SymfonyFile $file) => $file->getMTime()) + ->sortByDesc(fn (SymfonyFile $file) => $file->getMTime()) ->first(); $threshold = $this->youngestShouldHaveBeenMadeBefore->getTimestamp(); @@ -115,15 +113,13 @@ protected function youngestBackupIsToolOld(Collection $backups): bool } /** - * @param Collection $backups - * - * @return bool + * @param Collection $backups */ protected function oldestBackupIsTooYoung(Collection $backups): bool { /** @var SymfonyFile|null $oldestBackup */ $oldestBackup = $backups - ->sortBy(fn(SymfonyFile $file) => $file->getMTime()) + ->sortBy(fn (SymfonyFile $file) => $file->getMTime()) ->first(); $threshold = $this->oldestShouldHaveBeenMadeAfter->getTimestamp(); diff --git a/tests/Checks/BackupsCheckTest.php b/tests/Checks/BackupsCheckTest.php index ccffe4d6..c41ef33c 100644 --- a/tests/Checks/BackupsCheckTest.php +++ b/tests/Checks/BackupsCheckTest.php @@ -4,9 +4,10 @@ use Spatie\Health\Enums\Status; use Spatie\Health\Facades\Health; use Spatie\TemporaryDirectory\TemporaryDirectory; + use function Spatie\PestPluginTestTime\testTime; -beforeEach(function() { +beforeEach(function () { $this->backupsCheck = BackupsCheck::new(); Health::checks([ @@ -19,7 +20,7 @@ }); -it('it will succeed if a file with the given glob exist', function() { +it('it will succeed if a file with the given glob exist', function () { addTestFile($this->temporaryDirectory->path('hey.zip')); $result = $this->backupsCheck @@ -29,7 +30,7 @@ expect($result)->status->toBe(Status::ok()); }); -it('it will fail if a file with the given glob does not exist', function() { +it('it will fail if a file with the given glob does not exist', function () { addTestFile($this->temporaryDirectory->path('hey.other')); $result = $this->backupsCheck @@ -39,7 +40,7 @@ expect($result)->status->toBe(Status::failed()); }); -it('will fail if the given directory does not exist', function() { +it('will fail if the given directory does not exist', function () { $result = $this->backupsCheck ->locatedAt('non-existing-directory') ->run(); @@ -47,7 +48,7 @@ expect($result)->status->toBe(Status::failed()); }); -it('will fail if the backup is smaller than the given size', function() { +it('will fail if the backup is smaller than the given size', function () { addTestFile($this->temporaryDirectory->path('hey.zip'), sizeInMb: 4); $result = $this->backupsCheck @@ -58,7 +59,7 @@ expect($result)->status->toBe(Status::failed()); }); -it('will pass if the backup is at least than the given size', function(int $sizeInMb) { +it('will pass if the backup is at least than the given size', function (int $sizeInMb) { addTestFile($this->temporaryDirectory->path('hey.zip'), sizeInMb: $sizeInMb); $result = $this->backupsCheck @@ -72,7 +73,7 @@ [6], ]); -it('can check if the youngest backup is recent enough', function() { +it('can check if the youngest backup is recent enough', function () { addTestFile($this->temporaryDirectory->path('hey.zip')); testTime()->addMinutes(4); @@ -92,7 +93,7 @@ expect($result)->status->toBe(Status::failed()); }); -it('can check if the oldest backup is old enough', function() { +it('can check if the oldest backup is old enough', function () { addTestFile($this->temporaryDirectory->path('hey.zip'), date: now()->startOfMinute()); testTime()->addMinutes(4); @@ -113,7 +114,7 @@ expect($result)->status->toBe(Status::failed()); }); -it('can check that there are enough backups', function() { +it('can check that there are enough backups', function () { addTestFile($this->temporaryDirectory->path('first.zip')); $result = $this->backupsCheck @@ -130,6 +131,3 @@ ->run(); expect($result)->status->toBe(Status::ok()); }); - - - diff --git a/tests/Checks/DatabaseCheckTest.php b/tests/Checks/DatabaseCheckTest.php index 93dc0c2e..5135e773 100644 --- a/tests/Checks/DatabaseCheckTest.php +++ b/tests/Checks/DatabaseCheckTest.php @@ -2,7 +2,6 @@ use Spatie\Health\Checks\Checks\DatabaseCheck; use Spatie\Health\Enums\Status; -use function Spatie\PestPluginTestTime\testTime; it('will determine that a working database connection is ok', function () { $result = DatabaseCheck::new() diff --git a/tests/Pest.php b/tests/Pest.php index c85da5f8..8ddaa0e4 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -25,7 +25,7 @@ function getTemporaryDirectory(string $path = ''): string return __DIR__."/temp/{$path}"; } -function addTestFile(string $path, Carbon $date = null, int $sizeInMb = null): void +function addTestFile(string $path, ?Carbon $date = null, ?int $sizeInMb = null): void { $date = $date ?? now();