wiki.techinc.nl/tests/phpunit/unit/includes/auth/AuthenticationProviderTestTrait.php
vladshapik f4627f064c Create AuthenticationProviderTestTrait to facilitate testing of an AuthenticationProvider
Create new AuthenticationProviderTestTrait and AuthenticationProviderTestTrait
::initProvider method. Replace uses of AbstractAuthenticationProvider::init with new method in
tests.

Bug: T282781
Change-Id: Ie65c7558bfbacbf6678eea77e4a9b2cf68026456
2021-05-25 16:14:39 +03:00

50 lines
1.4 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Auth;
use Config;
use MediaWiki\Auth\AbstractAuthenticationProvider;
use MediaWiki\Auth\AuthManager;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\User\UserNameUtils;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* A trait providing utility function for testing subclasses of
* AbstractAuthenticationProvider. This trait is intended to be used on
* subclasses of MediaWikiIntegrationTestCase or MediaWikiUnitTestCase.
*
* @stable to use
* @package MediaWiki\Tests\Unit\Auth
*/
trait AuthenticationProviderTestTrait {
/**
* Calls init() on an AuthenticationProvider.
*
* @param AbstractAuthenticationProvider $provider
* @param Config|null $config
* @param LoggerInterface|null $logger
* @param AuthManager|null $manager
* @param HookContainer|null $hookContainer
* @param UserNameUtils|null $userNameUtils
*/
private function initProvider(
AbstractAuthenticationProvider $provider,
Config $config = null,
LoggerInterface $logger = null,
AuthManager $manager = null,
HookContainer $hookContainer = null,
UserNameUtils $userNameUtils = null
) {
$provider->init(
$logger ?? new NullLogger(),
$manager ?? $this->createNoOpMock( AuthManager::class ),
$hookContainer ?? $this->createHookContainer(),
$config ?? $this->createNoOpAbstractMock( Config::class ),
$userNameUtils ?? $this->createNoOpMock( UserNameUtils::class )
);
}
}