我的函数prepare()具有以下定义:
private function prepare(&$data, $conditions=null,
$conditionsRequired=false)
当我测试它时,这个
/**
* @covers /data/DB_Service::prepare
* @uses /inc/config
*/
public function testNoExceptionIsRaisedForValidPrepareWithConditionsAndConditionsRequiredArguments() {
$method = new ReflectionMethod('DB_Service', 'prepare');
$method->setAccessible(TRUE);
$dbs = new DB_Service(new Config(), array('admin', 'etl'));
$data = array('message' => '', 'sql' => array('full_query' => ""));
$method->invoke($dbs, $data, array('conditionKey' => 'conditionValue'), TRUE);
}
加注(并打破我的考验)
ReflectionException: Invocation of method DB_Service::prepare() failed
但是,这个
/**
* @covers /data/DB_Service::prepare
* @uses /inc/config
*/
public function testNoExceptionIsRaisedForValidPrepareWithConditionsAndConditionsRequiredArguments() {
$method = new ReflectionMethod('DB_Service', 'prepare');
$method->setAccessible(TRUE);
$dbs = new DB_Service(new Config(), array('admin', 'etl'));
//$data is no longer declared - the array is directly in the call below
$method->invoke($dbs, array('message' => '', 'sql' => array('full_query' => "")), array('conditionKey' => 'conditionValue'), TRUE);
}
工作完美,测试成功.
为什么声明变量然后传递不起作用,而只是在方法调用中创建它确实有效?我认为这与invoke()的工作原理有关,但我似乎无法弄清楚是什么.