Is PhpUnit a trait a good practice?

时间:2015-10-06 08:53:45

标签: php phpunit code-coverage traits xunit

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…

1 个答案:

答案 0 :(得分:1)

测试traits是一个非常有效的用例,PHPUnit使用getMockForTrait()方法有效地支持它。

https://phpunit.de/manual/current/en/test-doubles.html#test-doubles.mocking-traits-and-abstract-classes

如果另一个类覆盖了一个特征方法,你会在相关课程的测试用例中测试它,所以我不认为这会产生问题。

相关问题