From f4cc388eb9dfcfa69f279c6ced1a8b4734df05c9 Mon Sep 17 00:00:00 2001 From: Alangi Derick Date: Wed, 31 Oct 2018 14:22:47 +0100 Subject: [PATCH] auth: Follow up on e907d4328dc3e Updated unit tests as well for AuthManagerTest::testContinueAccountCreation() and AuthManagerTest::testContinueAccountLink(). Change-Id: I96363e34688517796c2812cb3f483e1bfa26be6b --- includes/auth/AuthManager.php | 12 ++++++------ .../auth/CreatedAccountAuthenticationRequest.php | 2 +- tests/phpunit/includes/auth/AuthManagerTest.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index aae5a83a22..32592ac770 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -1213,7 +1213,7 @@ class AuthManager implements LoggerAwareInterface { $user->load( User::READ_LOCKING ); if ( $state['userid'] === 0 ) { - if ( $user->getId() != 0 ) { + if ( $user->getId() !== 0 ) { $this->logger->debug( __METHOD__ . ': User exists locally', [ 'user' => $user->getName(), 'creator' => $creator->getName(), @@ -1234,7 +1234,7 @@ class AuthManager implements LoggerAwareInterface { "User \"{$state['username']}\" should exist now, but doesn't!" ); } - if ( $user->getId() != $state['userid'] ) { + if ( $user->getId() !== $state['userid'] ) { $this->logger->debug( __METHOD__ . ': User ID/name mismatch', [ 'user' => $user->getName(), 'creator' => $creator->getName(), @@ -1243,7 +1243,7 @@ class AuthManager implements LoggerAwareInterface { ] ); throw new \UnexpectedValueException( "User \"{$state['username']}\" exists, but " . - "ID {$user->getId()} != {$state['userid']}!" + "ID {$user->getId()} !== {$state['userid']}!" ); } } @@ -1565,7 +1565,7 @@ class AuthManager implements LoggerAwareInterface { // @codeCoverageIgnoreStart if ( !$localId && - MediaWikiServices::getInstance()->getDBLoadBalancer()->getReaderIndex() != 0 + MediaWikiServices::getInstance()->getDBLoadBalancer()->getReaderIndex() !== 0 ) { $localId = User::idFromName( $username, User::READ_LATEST ); $flags = User::READ_LATEST; @@ -1930,10 +1930,10 @@ class AuthManager implements LoggerAwareInterface { $session->remove( 'AuthManager::accountLinkState' ); return AuthenticationResponse::newFail( wfMessage( 'noname' ) ); } - if ( $user->getId() != $state['userid'] ) { + if ( $user->getId() !== $state['userid'] ) { throw new \UnexpectedValueException( "User \"{$state['username']}\" is valid, but " . - "ID {$user->getId()} != {$state['userid']}!" + "ID {$user->getId()} !== {$state['userid']}!" ); } diff --git a/includes/auth/CreatedAccountAuthenticationRequest.php b/includes/auth/CreatedAccountAuthenticationRequest.php index 48a6e1d36c..a7d24842bb 100644 --- a/includes/auth/CreatedAccountAuthenticationRequest.php +++ b/includes/auth/CreatedAccountAuthenticationRequest.php @@ -42,7 +42,7 @@ class CreatedAccountAuthenticationRequest extends AuthenticationRequest { * @param string $name Username */ public function __construct( $id, $name ) { - $this->id = $id; + $this->id = (int)$id; $this->username = $name; } } diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index 6bdc5695d9..564336e3b1 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -15,7 +15,7 @@ use Wikimedia\TestingAccessWrapper; /** * @group AuthManager * @group Database - * @covers MediaWiki\Auth\AuthManager + * @covers \MediaWiki\Auth\AuthManager */ class AuthManagerTest extends \MediaWikiTestCase { /** @var WebRequest */ @@ -1831,7 +1831,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $this->fail( 'Expected exception not thrown' ); } catch ( \UnexpectedValueException $ex ) { $this->assertEquals( - "User \"{$name}\" exists, but ID $id != " . ( $id + 1 ) . '!', $ex->getMessage() + "User \"{$name}\" exists, but ID $id !== " . ( $id + 1 ) . '!', $ex->getMessage() ); } $this->unhook( 'LocalUserCreated' ); @@ -3384,7 +3384,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $this->fail( 'Expected exception not thrown' ); } catch ( \UnexpectedValueException $ex ) { $this->assertEquals( - "User \"{$user->getName()}\" is valid, but ID $id != " . ( $id + 1 ) . '!', + "User \"{$user->getName()}\" is valid, but ID $id !== " . ( $id + 1 ) . '!', $ex->getMessage() ); } -- 2.20.1