Update# testing: use returnCallback() to mock IConfig

This commit is contained in:
Pellaeon Lin 2018-06-30 17:41:31 +08:00
parent 3bb6bc8026
commit 3e9f594163
1 changed files with 11 additions and 18 deletions

View File

@ -200,27 +200,11 @@ class RegistrationServiceTest extends TestCase {
//$reg->setPassword("asdf");
$reg->setEmailConfirmed(true);
/*
$map = [
["registration", 'registered_user_group', 'none'],
["registration", 'admin_approval_required', 'no']
];
*/
$this->config->expects($this->at(0))
$this->config->expects($this->atLeastOnce())
->method('getAppValue')
->with("registration", 'registered_user_group', 'none')
->willReturn('none');
$this->config->expects($this->at(1))
->method('getAppValue')
->with("registration", 'admin_approval_required', 'no')
->willReturn('no');
->will($this->returnCallback(array($this, 'settingsCallback1')));
//$regroup = $this->config->getAppValue("registration", 'registered_user_group', 'none');
//print_r($regroup);
//$this->assertEquals($this->config->getAppValue('registration', 'registered_user_group', 'none'), "none");
$form_input_username = 'alice1';
$resulting_user = $this->service->createAccount($reg, $form_input_username, 'asdf');
@ -266,4 +250,13 @@ class RegistrationServiceTest extends TestCase {
$resulting_user = $this->service->createAccount($reg);
}
public function settingsCallback1($app, $key, $default) {
$map = [
'registered_user_group' => 'none',
'admin_approval_required' => 'no'
];
return $map[$key];
}
}