<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\Note;
use App\Models\User;
class NoteTest extends TestCase
{
use RefreshDatabase;
protected $user;
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
// var_dump("awal");
}
protected function tearDown(): void
{
parent::tearDown();
unset($this->user);
// var_dump("akhir");
}
/**
* @test
* @group test1
*/
public function a_note_can_be_created()
{
// var_dump("create");
$this->withoutExceptionHandling();
$response = $this->actingAs($this->user)->post('/notes', [
'note' => 'Test Note'
]);
$response->assertRedirect('/notes');
$this->assertCount(1, Note::all());
}
/**
* @test
* @group test1
*/
public function a_note_can_be_updated()
{
// var_dump("update");
$this->withoutExceptionHandling();
$this->actingAs($this->user)->post('/notes', [
'note' => 'Test Note'
]);
$note = Note::first();
$response = $this->actingAs($this->user)->put('/notes/' . $note->id, [
'note' => 'Updated Note'
]);
$response->assertRedirect('/notes/' . $note->id);
$this->assertEquals('Updated Note', Note::first()->note);
}
/**
* @test
* @group test2
*/
public function a_note_can_be_deleted()
{
// var_dump("delete");
$this->withoutExceptionHandling();
$this->actingAs($this->user)->post('/notes', [
'note' => 'Test Note'
]);
$note = Note::first();
$response = $this->actingAs($this->user)->delete('/notes/' . $note->id);
$response->assertRedirect('/notes');
$this->assertCount(0, Note::all());
}
}