Skip to content

Instantly share code, notes, and snippets.

@jsdecena
Created October 31, 2025 00:57
Show Gist options
  • Select an option

  • Save jsdecena/39165251985453581c75fc6042a517d4 to your computer and use it in GitHub Desktop.

Select an option

Save jsdecena/39165251985453581c75fc6042a517d4 to your computer and use it in GitHub Desktop.
sample unit testing
<?php
namespace Tests\Unit\Sales;
use Tests\TestCase;
class CreditNoteUnitTest extends TestCase
{
/** @test */
public function it_should_set_status_deleted_when_deleting_credit_note()
{
// factory
$creditNote = CreditNote::factory()->create(['reference' => '123']);
$creditNoteRepository = new CreditNoteRepository();
$creditNote = $creditNoteRepository->find($creditNote->id);
$isUpdated = $creditNoteReposirory->update(['status' => 'deleted']);
$this->assertEquals('deleted', $creditNote->status);
}
}
// Controller
public function delete_credit_note($id)
{
$credit_note = $this->creditNoteRepository->find($creditNote->id);
if (!$credit_note) {
return response()->json(['error' => 'Credit note not found.'], 404);
}
$isUpdated = $creditNoteReposirory->update(['status' => CreditNote::deleted]);
return response()->json(['success' => true, 'message' => 'Credit note has been deleted successfully.']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment