In a project, we use three traits used by approximatively ten similar class (but the classes aren't working exactly in the same way).
We use trait because that's a way for communicate with 10 differents others company and all of them don't use the same input-format for receive ours datas. That's a way for us to standardize some methods according to different use cases.
I want to cover a trait with some phpUnit tests because I want to test «The default use case of a class that use the trait».
For me it's a good point to cover the default use case of a method in a trait.
If my class who use the trait are surcharging my trait-method, that's another problem, the case need to be cover too in my opinion.
So here is my question : Is this is a good practice for you to cover a trait with PhpUnit?
sorry for my bad English…
答案 0 :(得分:1)
测试traits是一个非常有效的用例,PHPUnit使用getMockForTrait()
方法有效地支持它。
如果另一个类覆盖了一个特征方法,你会在相关课程的测试用例中测试它,所以我不认为这会产生问题。