Created
October 31, 2025 00:57
-
-
Save jsdecena/39165251985453581c75fc6042a517d4 to your computer and use it in GitHub Desktop.
sample unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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