Laravel 5.1 testing with PHPUnit and PHPSpec

750 views Asked by At

Laravel 5.1 have been released. But I don't know how to use it's testing features because I'm still new with TDD stuffs.

For example, I want to test my Eloquent Model (relationships etc.) Anyone could explain with clear explanation? Thanks in advance

1

There are 1 answers

0
Mohammad.Kaab On

There is a couple of type of testing we have in the world, What I would suggest you do is to write a unit test, for example, let's say you have users and posts table and you want to test the relationship.

$user = factory(User::class)->create();
$post = factory(Post::class)->create(['user_id'=>$user_id]);

$this->assertEqual(1, $user->posts->count());

This way you have tested the relationship between user and posts.