5 use Psr\Log\LoggerInterface;
6 use Wikimedia\TestingAccessWrapper;
19 session_write_close();
21 $rInstance = new \ReflectionProperty(
24 $rInstance->setAccessible(
true );
25 $rGlobalSession = new \ReflectionProperty(
28 $rGlobalSession->setAccessible(
true );
29 $rGlobalSessionRequest = new \ReflectionProperty(
32 $rGlobalSessionRequest->setAccessible(
true );
34 $oldInstance = $rInstance->getValue();
37 [ $rInstance, $oldInstance ],
38 [ $rGlobalSession, $rGlobalSession->getValue() ],
39 [ $rGlobalSessionRequest, $rGlobalSessionRequest->getValue() ],
42 $rInstance->setValue( $manager );
43 $rGlobalSession->setValue(
null );
44 $rGlobalSessionRequest->setValue(
null );
49 return new \Wikimedia\ScopedCallback(
function ()
use ( &$reset, $oldInstance ) {
50 foreach ( $reset
as &$arr ) {
51 $arr[0]->setValue( $arr[1] );
67 if ( !method_exists( $rc,
'newInstanceWithoutConstructor' ) ) {
68 \PHPUnit_Framework_Assert::markTestSkipped(
69 'ReflectionClass::newInstanceWithoutConstructor isn\'t available'
73 $ret = $rc->newInstanceWithoutConstructor();
74 TestingAccessWrapper::newFromObject(
$ret )->logger = new \TestLogger;
86 public static function getDummySession( $backend =
null, $index = -1, $logger =
null ) {
88 if ( !method_exists( $rc,
'newInstanceWithoutConstructor' ) ) {
89 \PHPUnit_Framework_Assert::markTestSkipped(
90 'ReflectionClass::newInstanceWithoutConstructor isn\'t available'
94 if ( $backend ===
null ) {
98 $session = $rc->newInstanceWithoutConstructor();
99 $priv = TestingAccessWrapper::newFromObject( $session );
100 $priv->backend = $backend;
101 $priv->index = $index;
102 $priv->logger = $logger ?: new \TestLogger;