Skip to content

Commit

Permalink
Complete logs & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubka committed Sep 2, 2024
1 parent e0d2786 commit 21d6816
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/Services/TwoFAccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down
17 changes: 15 additions & 2 deletions tests/Feature/Services/TwoFAccountServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 21d6816

Please sign in to comment.