开发者

@depends flag breaks the arguments in my PHPUnit function

开发者 https://www.devze.com 2023-04-06 12:01 出处:网络
In the code below, testFunctionA outputs true, while testFunctionB outputs nu开发者_如何学运维ll. Is this a known error and can I get around it without getting rid of my @depends flags?

In the code below, testFunctionA outputs true, while testFunctionB outputs nu开发者_如何学运维ll. Is this a known error and can I get around it without getting rid of my @depends flags?

public function testFunctionA( $x = true ) {
  var_dump( $x ); // outputs true
}

/*
* @depends testFunctionA
*/
public function testFunctionB( $y = true ) {
  var_dump( $y ); // outputs NULL
}


The @depends annotation does a bit more than you are thinking it does here. Mainly, the return value from testFunctionA is passed into testFunctionB. Since testFunctionA doesn't return anything, testFunctionB is getting passed a null value.

See the PHPUnit test dependencies docs for more information.

There is a difference between providing a null parameter and no parameter at all to testFunctionB. Only with nothing provided will $y default to true.

0

精彩评论

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