Herkese merhaba tdd ile uygulama geliştiriyorum öğrenmek için fakat şöyle bir sıkıntım var.
public function store()
{
$thread = Thread::create([
'user_id' => auth()->id(),
'title' => request('title'),
'body' => request('body'),
'channel_id' => request('channel_id')
]);
//dd(Thread::find($thread->id))
return view('threads.show', compact('thread'));
}
Benim bir adet $thread oluşturduğum methodum bu ve bu sorunsuz bir şekilde çalışıyor fakat bu işlem için yazmış olduğum testte ise bu method sorun ile sorunum var çünkü db'ye $thread'i girmiyor.
Aslında eğer ben test için buraya dd(Thread::find($thread->id))
dersem terminalde $thread'i görüyorum yani çalışıyor mu çalışmıyor mu anlamadım $thread'i dump ettiğine göre çalıştığını düşünüyorum.
public function an_unauthenticated_user_can_create_new_forum_threads()
{
$this->actingAs(create(User::class));
$thread = Thread::factory()->make();
$this->post('/threads', $thread->toArray());
$response = $this->get("/thread/$thread->id");
//dd(Thread::find($thread->id));
$response->assertSee($thread->title);
$response->assertSee($thread->body);
}
Burada $thread'i make ile oluşturup $thread array'ini gerekli endpoint'e post ediyorum fakat terminalde ./vendor/bin/phpunit --filter an_unauthenticated_user_can_create_new_forum_threads
ile testi çalıştırıp //dd(Thread::find($thread->id));
'i
dump ettiriyorum ve 'null'
çıkıyor.Testte sorun çıkıyor ama uygulamada sıkıntı yok browserda sorunsuz.
Sebebi nedir acaba ?
Bu arada aslında sorun yok evet sonuçta çalışıyor ama test yazmayı öğrendiğim için yazdığım testin neden çalışmadığını anlamaya çalışıyorum.
use DatabaseMigrations;
yada use RefreshDatabase;
kullanıyorum fakat fark yok.Diğer testlerimdeki get requestleride çalışıyor bu arada.
Başlığı yanlış atmışım Local yerine browser daha doğru olurdu