From 8180e6450da67cae51e47f321571d5f278f95b99 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Fri, 13 Sep 2024 12:51:48 +0200 Subject: [PATCH] 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 --- .../CaptchaPreAuthenticationProviderTest.php | 13 +++++++++---- tests/phpunit/SimpleCaptcha/CaptchaTest.php | 12 +++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/CaptchaPreAuthenticationProviderTest.php b/tests/phpunit/CaptchaPreAuthenticationProviderTest.php index c6cbf0823..a1a6843d4 100644 --- a/tests/phpunit/CaptchaPreAuthenticationProviderTest.php +++ b/tests/phpunit/CaptchaPreAuthenticationProviderTest.php @@ -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; diff --git a/tests/phpunit/SimpleCaptcha/CaptchaTest.php b/tests/phpunit/SimpleCaptcha/CaptchaTest.php index ef2c540eb..a61b72c10 100644 --- a/tests/phpunit/SimpleCaptcha/CaptchaTest.php +++ b/tests/phpunit/SimpleCaptcha/CaptchaTest.php @@ -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' ); } }