简体   繁体   English

Laravel 5.1 使用 PHPUnit 和 PHPSpec 进行测试

[英]Laravel 5.1 testing with PHPUnit and PHPSpec

Laravel 5.1 have been released. Laravel 5.1 已经发布。 But I don't know how to use it's testing features because I'm still new with TDD stuffs.但我不知道如何使用它的测试功能,因为我对 TDD 还是个新手。

For example, I want to test my Eloquent Model (relationships etc.) Anyone could explain with clear explanation?例如,我想测试我的 Eloquent 模型(关系等)。谁能解释清楚? Thanks in advance提前致谢

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.这样你就测试了用户和帖子之间的关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM