From 3e9f594163f948680f50002b3c182f170e06864b Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sat, 30 Jun 2018 17:41:31 +0800 Subject: [PATCH] Update# testing: use returnCallback() to mock IConfig --- .../service/RegistrationServiceTest.php | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/integration/service/RegistrationServiceTest.php b/tests/integration/service/RegistrationServiceTest.php index 9be5a25..59f04ba 100644 --- a/tests/integration/service/RegistrationServiceTest.php +++ b/tests/integration/service/RegistrationServiceTest.php @@ -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]; + } }