Fix confusing usages of TestingAccessWrapper

Some of this is not necessary at all because all properties are
public anyway.

In other cases only one property needs to use the wrapper, the rest
is public and can be accessed normally.

In other cases we just missed the @var annotation to make the IDE
aware of what's actually going on.

Change-Id: I29b526ee3aad9f0c9671fb133c625b9f14309db9
This commit is contained in:
thiemowmde 2024-09-13 12:51:48 +02:00 committed by Thiemo Kreuz (WMDE)
parent 498dac5cc1
commit 8180e6450d
2 changed files with 14 additions and 11 deletions

View file

@ -36,8 +36,10 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
public function tearDown(): void {
parent::tearDown();
/** @var Hooks $req */
$req = TestingAccessWrapper::newFromClass( Hooks::class );
// make sure $wgCaptcha resets between tests
TestingAccessWrapper::newFromClass( Hooks::class )->instanceCreated = false;
$req->instanceCreated = false;
}
/**
@ -102,10 +104,12 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
[ 'username' => 'Foo' ] );
$this->assertCount( 1, $reqs );
$this->assertInstanceOf( CaptchaAuthenticationRequest::class, $reqs[0] );
/** @var CaptchaAuthenticationRequest $req */
$req = $reqs[0];
$this->assertInstanceOf( CaptchaAuthenticationRequest::class, $req );
$id = $reqs[0]->captchaId;
$data = TestingAccessWrapper::newFromObject( $reqs[0] )->captchaData;
$id = $req->captchaId;
$data = $req->captchaData;
$this->assertEquals( $captcha->retrieveCaptcha( $id ), $data + [ 'index' => $id ] );
}
@ -241,6 +245,7 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
);
$provider = new CaptchaPreAuthenticationProvider();
$this->initProvider( $provider, null, null, $this->getServiceContainer()->getAuthManager() );
/** @var CaptchaPreAuthenticationProvider $providerAccess */
$providerAccess = TestingAccessWrapper::newFromObject( $provider );
$disablePingLimiter = false;

View file

@ -171,10 +171,10 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
'edit' => true,
] );
$testObject = new SimpleCaptcha();
/** @var SimpleCaptcha|TestingAccessWrapper $wrapper */
/** @var SimpleCaptcha $wrapper */
$wrapper = TestingAccessWrapper::newFromObject( $testObject );
$wrapper->captchaSolved = true;
$this->assertFalse( $wrapper->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered if already solved' );
$this->assertFalse( $testObject->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered if already solved' );
}
public function testForceShowCaptcha() {
@ -182,12 +182,10 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
'edit' => false,
] );
$testObject = new SimpleCaptcha();
/** @var SimpleCaptcha|TestingAccessWrapper $wrapper */
$wrapper = TestingAccessWrapper::newFromObject( $testObject );
$this->assertFalse(
$wrapper->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered by edit action in this configuration'
$testObject->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered by edit action in this configuration'
);
$wrapper->setForceShowCaptcha( true );
$this->assertTrue( $wrapper->triggersCaptcha( 'edit' ), 'Force showing a CAPTCHA if flag is set' );
$testObject->setForceShowCaptcha( true );
$this->assertTrue( $testObject->triggersCaptcha( 'edit' ), 'Force showing a CAPTCHA if flag is set' );
}
}