本文整理汇总了PHP中TestingAccessWrapper::getSecondaryAuthenticationProviders方法的典型用法代码示例。如果您正苦于以下问题:PHP TestingAccessWrapper::getSecondaryAuthenticationProviders方法的具体用法?PHP TestingAccessWrapper::getSecondaryAuthenticationProviders怎么用?PHP TestingAccessWrapper::getSecondaryAuthenticationProviders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestingAccessWrapper
的用法示例。
在下文中一共展示了TestingAccessWrapper::getSecondaryAuthenticationProviders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProviderCreation
public function testProviderCreation()
{
$mocks = ['pre' => $this->getMockForAbstractClass(PreAuthenticationProvider::class), 'primary' => $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class), 'secondary' => $this->getMockForAbstractClass(SecondaryAuthenticationProvider::class)];
foreach ($mocks as $key => $mock) {
$mock->expects($this->any())->method('getUniqueId')->will($this->returnValue($key));
$mock->expects($this->once())->method('setLogger');
$mock->expects($this->once())->method('setManager');
$mock->expects($this->once())->method('setConfig');
}
$this->preauthMocks = [$mocks['pre']];
$this->primaryauthMocks = [$mocks['primary']];
$this->secondaryauthMocks = [$mocks['secondary']];
// Normal operation
$this->initializeManager();
$this->assertSame($mocks['primary'], $this->managerPriv->getAuthenticationProvider('primary'));
$this->assertSame($mocks['secondary'], $this->managerPriv->getAuthenticationProvider('secondary'));
$this->assertSame($mocks['pre'], $this->managerPriv->getAuthenticationProvider('pre'));
$this->assertSame(['pre' => $mocks['pre']], $this->managerPriv->getPreAuthenticationProviders());
$this->assertSame(['primary' => $mocks['primary']], $this->managerPriv->getPrimaryAuthenticationProviders());
$this->assertSame(['secondary' => $mocks['secondary']], $this->managerPriv->getSecondaryAuthenticationProviders());
// Duplicate IDs
$mock1 = $this->getMockForAbstractClass(PreAuthenticationProvider::class);
$mock2 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mock1->expects($this->any())->method('getUniqueId')->will($this->returnValue('X'));
$mock2->expects($this->any())->method('getUniqueId')->will($this->returnValue('X'));
$this->preauthMocks = [$mock1];
$this->primaryauthMocks = [$mock2];
$this->secondaryauthMocks = [];
$this->initializeManager(true);
try {
$this->managerPriv->getAuthenticationProvider('Y');
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$class1 = get_class($mock1);
$class2 = get_class($mock2);
$this->assertSame("Duplicate specifications for id X (classes {$class1} and {$class2})", $ex->getMessage());
}
// Wrong classes
$mock = $this->getMockForAbstractClass(AuthenticationProvider::class);
$mock->expects($this->any())->method('getUniqueId')->will($this->returnValue('X'));
$class = get_class($mock);
$this->preauthMocks = [$mock];
$this->primaryauthMocks = [$mock];
$this->secondaryauthMocks = [$mock];
$this->initializeManager(true);
try {
$this->managerPriv->getPreAuthenticationProviders();
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$this->assertSame("Expected instance of MediaWiki\\Auth\\PreAuthenticationProvider, got {$class}", $ex->getMessage());
}
try {
$this->managerPriv->getPrimaryAuthenticationProviders();
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$this->assertSame("Expected instance of MediaWiki\\Auth\\PrimaryAuthenticationProvider, got {$class}", $ex->getMessage());
}
try {
$this->managerPriv->getSecondaryAuthenticationProviders();
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$this->assertSame("Expected instance of MediaWiki\\Auth\\SecondaryAuthenticationProvider, got {$class}", $ex->getMessage());
}
// Sorting
$mock1 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mock2 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mock3 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mock1->expects($this->any())->method('getUniqueId')->will($this->returnValue('A'));
$mock2->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
$mock3->expects($this->any())->method('getUniqueId')->will($this->returnValue('C'));
$this->preauthMocks = [];
$this->primaryauthMocks = [$mock1, $mock2, $mock3];
$this->secondaryauthMocks = [];
$this->initializeConfig();
$config = $this->config->get('AuthManagerConfig');
$this->initializeManager(false);
$this->assertSame(['A' => $mock1, 'B' => $mock2, 'C' => $mock3], $this->managerPriv->getPrimaryAuthenticationProviders(), 'sanity check');
$config['primaryauth']['A']['sort'] = 100;
$config['primaryauth']['C']['sort'] = -1;
$this->config->set('AuthManagerConfig', $config);
$this->initializeManager(false);
$this->assertSame(['C' => $mock3, 'B' => $mock2, 'A' => $mock1], $this->managerPriv->getPrimaryAuthenticationProviders());
}