Complete logs & tests

This commit is contained in:
Bubka 2024-09-02 10:11:30 +02:00
parent e0d2786fe5
commit 21d6816151
2 changed files with 20 additions and 4 deletions

View File

@ -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)));
}
/**

View File

@ -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]