diff --git a/app/Services/TwoFAccountService.php b/app/Services/TwoFAccountService.php index 451621f7..72311428 100644 --- a/app/Services/TwoFAccountService.php +++ b/app/Services/TwoFAccountService.php @@ -39,12 +39,15 @@ public static function withdraw($ids) : void // whereIn() expects an array $ids = is_array($ids) ? $ids : func_get_args(); - TwoFAccount::whereIn('id', $ids) + $affectedCount = TwoFAccount::whereIn('id', $ids) ->update( ['group_id' => null] ); - Log::info(sprintf('TwoFAccounts IDs #%s withdrawn', implode(',', $ids))); + if ($affectedCount) { + Log::info(sprintf('TwoFAccounts with IDs #%s withdrawn', implode(',', $ids))); + } + else Log::info(sprintf('Cannot find TwoFAccounts to withdraw using ids #%s', implode(',', $ids))); } /** diff --git a/tests/Feature/Services/TwoFAccountServiceTest.php b/tests/Feature/Services/TwoFAccountServiceTest.php index a07b221b..40aa329f 100644 --- a/tests/Feature/Services/TwoFAccountServiceTest.php +++ b/tests/Feature/Services/TwoFAccountServiceTest.php @@ -7,6 +7,7 @@ use App\Models\TwoFAccount; use App\Models\User; use App\Services\TwoFAccountService; +use Illuminate\Support\Facades\Exceptions; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use Tests\Data\MigrationTestData; @@ -151,9 +152,21 @@ public function test_withdraw_single_id_deletes_relation() } #[Test] - public function test_withdraw_missing_ids_returns_void() + public function test_withdraw_missing_ids_does_not_throw_exception() { - $this->assertNull(TwoFAccounts::withdraw(null)); + Exceptions::fake(); + Exceptions::assertNothingReported(); + + TwoFAccounts::withdraw(9999999); + } + + #[Test] + public function test_withdraw_null_id_does_not_throw_exception() + { + Exceptions::fake(); + Exceptions::assertNothingReported(); + + TwoFAccounts::withdraw(null); } #[Test]