开发者

how to unit testing function that doesn't return value in phpunit?

开发者 https://www.devze.com 2023-02-25 08:42 出处:网络
so this is the class that i want to test. and specifically i just pick one of the function that i want to test. while var is a value returned from doing some function from classB bar is instance from

so this is the class that i want to test. and specifically i just pick one of the function that i want to test. while var is a value returned from doing some function from classB bar is instance from classC and then do some function which pass some variables. for most of the hints/example, the function to be tested is return a val开发者_运维知识库ue. so my question is, how to test that this particular function worked?

thanks.

class mA extends A {
    ...
    function doSomething($foo) {
        $var = doStuffFromClassB("hallo");
        $bar = ClassC::instance();
        $bar->doStuffFromClassC($var, $foo, "world");
    }
}


If it's called doSomething and it doesn't indicate what it does by returning a value, then you can use mock objects to trace the interaction with the other objects.

See PhpUnit's documentation on mock objects. I guess in this case you want to verify that the doStuffFromClassC method is involved with the var from doStuffFromClassB.

0

精彩评论

暂无评论...
验证码 换一张
取 消