本文整理汇总了PHP中TestingAccessWrapper::getPrimaryAuthenticationProviders方法的典型用法代码示例。如果您正苦于以下问题:PHP TestingAccessWrapper::getPrimaryAuthenticationProviders方法的具体用法?PHP TestingAccessWrapper::getPrimaryAuthenticationProviders怎么用?PHP TestingAccessWrapper::getPrimaryAuthenticationProviders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestingAccessWrapper
的用法示例。
在下文中一共展示了TestingAccessWrapper::getPrimaryAuthenticationProviders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testForcePrimaryAuthenticationProviders
public function testForcePrimaryAuthenticationProviders()
{
$mockA = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mockB = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mockB2 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
$mockA->expects($this->any())->method('getUniqueId')->will($this->returnValue('A'));
$mockB->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
$mockB2->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
$this->primaryauthMocks = [$mockA];
$this->logger = new \TestLogger(true);
// Test without first initializing the configured providers
$this->initializeManager();
$this->manager->forcePrimaryAuthenticationProviders([$mockB], 'testing');
$this->assertSame(['B' => $mockB], $this->managerPriv->getPrimaryAuthenticationProviders());
$this->assertSame(null, $this->managerPriv->getAuthenticationProvider('A'));
$this->assertSame($mockB, $this->managerPriv->getAuthenticationProvider('B'));
$this->assertSame([[LogLevel::WARNING, 'Overriding AuthManager primary authn because testing']], $this->logger->getBuffer());
$this->logger->clearBuffer();
// Test with first initializing the configured providers
$this->initializeManager();
$this->assertSame($mockA, $this->managerPriv->getAuthenticationProvider('A'));
$this->assertSame(null, $this->managerPriv->getAuthenticationProvider('B'));
$this->request->getSession()->setSecret('AuthManager::authnState', 'test');
$this->request->getSession()->setSecret('AuthManager::accountCreationState', 'test');
$this->manager->forcePrimaryAuthenticationProviders([$mockB], 'testing');
$this->assertSame(['B' => $mockB], $this->managerPriv->getPrimaryAuthenticationProviders());
$this->assertSame(null, $this->managerPriv->getAuthenticationProvider('A'));
$this->assertSame($mockB, $this->managerPriv->getAuthenticationProvider('B'));
$this->assertNull($this->request->getSession()->getSecret('AuthManager::authnState'));
$this->assertNull($this->request->getSession()->getSecret('AuthManager::accountCreationState'));
$this->assertSame([[LogLevel::WARNING, 'Overriding AuthManager primary authn because testing'], [LogLevel::WARNING, 'PrimaryAuthenticationProviders have already been accessed! I hope nothing breaks.']], $this->logger->getBuffer());
$this->logger->clearBuffer();
// Test duplicate IDs
$this->initializeManager();
try {
$this->manager->forcePrimaryAuthenticationProviders([$mockB, $mockB2], 'testing');
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$class1 = get_class($mockB);
$class2 = get_class($mockB2);
$this->assertSame("Duplicate specifications for id B (classes {$class2} and {$class1})", $ex->getMessage());
}
// Wrong classes
$mock = $this->getMockForAbstractClass(AuthenticationProvider::class);
$mock->expects($this->any())->method('getUniqueId')->will($this->returnValue('X'));
$class = get_class($mock);
try {
$this->manager->forcePrimaryAuthenticationProviders([$mock], 'testing');
$this->fail('Expected exception not thrown');
} catch (\RuntimeException $ex) {
$this->assertSame("Expected instance of MediaWiki\\Auth\\PrimaryAuthenticationProvider, got {$class}", $ex->getMessage());
}
}