namespace MediaWiki\Session;
+use Psr\Log\LoggerInterface;
+
/**
* Utility functions for Session unit tests
*/
/**
* Override the singleton for unit testing
* @param SessionManager|null $manager
- * @return \\ScopedCallback|null
+ * @return \\Wikimedia\ScopedCallback|null
*/
public static function setSessionManagerSingleton( SessionManager $manager = null ) {
session_write_close();
$rInstance = new \ReflectionProperty(
- 'MediaWiki\\Session\\SessionManager', 'instance'
+ SessionManager::class, 'instance'
);
$rInstance->setAccessible( true );
$rGlobalSession = new \ReflectionProperty(
- 'MediaWiki\\Session\\SessionManager', 'globalSession'
+ SessionManager::class, 'globalSession'
);
$rGlobalSession->setAccessible( true );
$rGlobalSessionRequest = new \ReflectionProperty(
- 'MediaWiki\\Session\\SessionManager', 'globalSessionRequest'
+ SessionManager::class, 'globalSessionRequest'
);
$rGlobalSessionRequest->setAccessible( true );
$oldInstance = $rInstance->getValue();
- $reset = array(
- array( $rInstance, $oldInstance ),
- array( $rGlobalSession, $rGlobalSession->getValue() ),
- array( $rGlobalSessionRequest, $rGlobalSessionRequest->getValue() ),
- );
+ $reset = [
+ [ $rInstance, $oldInstance ],
+ [ $rGlobalSession, $rGlobalSession->getValue() ],
+ [ $rGlobalSessionRequest, $rGlobalSessionRequest->getValue() ],
+ ];
$rInstance->setValue( $manager );
$rGlobalSession->setValue( null );
PHPSessionHandler::install( $manager );
}
- return new \ScopedCallback( function () use ( &$reset, $oldInstance ) {
+ return new \Wikimedia\ScopedCallback( function () use ( &$reset, $oldInstance ) {
foreach ( $reset as &$arr ) {
$arr[0]->setValue( $arr[1] );
}
* fields necessary.
*/
public static function getDummySessionBackend() {
- $rc = new \ReflectionClass( 'MediaWiki\\Session\\SessionBackend' );
+ $rc = new \ReflectionClass( SessionBackend::class );
if ( !method_exists( $rc, 'newInstanceWithoutConstructor' ) ) {
\PHPUnit_Framework_Assert::markTestSkipped(
'ReflectionClass::newInstanceWithoutConstructor isn\'t available'
);
}
- return $rc->newInstanceWithoutConstructor();
+ $ret = $rc->newInstanceWithoutConstructor();
+ \TestingAccessWrapper::newFromObject( $ret )->logger = new \TestLogger;
+ return $ret;
}
/**
* construct one, use this.
* @param object $backend Object to serve as the SessionBackend
* @param int $index Index
+ * @param LoggerInterface $logger
* @return Session
*/
- public static function getDummySession( $backend = null, $index = -1 ) {
- $rc = new \ReflectionClass( 'MediaWiki\\Session\\Session' );
+ public static function getDummySession( $backend = null, $index = -1, $logger = null ) {
+ $rc = new \ReflectionClass( Session::class );
if ( !method_exists( $rc, 'newInstanceWithoutConstructor' ) ) {
\PHPUnit_Framework_Assert::markTestSkipped(
'ReflectionClass::newInstanceWithoutConstructor isn\'t available'
$priv = \TestingAccessWrapper::newFromObject( $session );
$priv->backend = $backend;
$priv->index = $index;
+ $priv->logger = $logger ?: new \TestLogger;
return $session;
}