Don't create user in AuthManagerTest dataProvider
authoraude <aude.wiki@gmail.com>
Sat, 18 Mar 2017 18:26:25 +0000 (14:26 -0400)
committeraude <aude.wiki@gmail.com>
Sat, 18 Mar 2017 19:45:04 +0000 (15:45 -0400)
Creating users involves database access and the test
database isn't fully setup yet when data providers run.

In this particular test / data provider, all that is needed
is the user name so we can just set that w/o creating
the user in the data provider. The user gets created during
the test. (after the test database is setup)

also $id set in $id = $user->getId() was unused and was the
specific code that involved making a database connection.

Change-Id: I1685dfdd6cfc60cd2c59a4d9de95bcbbaba5e153

tests/phpunit/includes/auth/AuthManagerTest.php

index f57db11..f7be801 100644 (file)
@@ -1083,10 +1083,6 @@ class AuthManagerTest extends \MediaWikiTestCase {
        }
 
        public function provideAuthentication() {
-               $user = \User::newFromName( 'UTSysop' );
-               $id = $user->getId();
-               $name = $user->getName();
-
                $rememberReq = new RememberMeAuthenticationRequest;
                $rememberReq->action = AuthManager::ACTION_LOGIN;
 
@@ -1108,6 +1104,8 @@ class AuthManagerTest extends \MediaWikiTestCase {
                $restartResponse2->createRequest->action = AuthManager::ACTION_LOGIN;
                $restartResponse2->neededRequests = [ $rememberReq, $restartResponse2->createRequest ];
 
+               $userName = 'UTSysop';
+
                return [
                        'Failure in pre-auth' => [
                                StatusValue::newFatal( 'fail-from-pre' ),
@@ -1202,7 +1200,7 @@ class AuthManagerTest extends \MediaWikiTestCase {
                        'Secondary fail' => [
                                StatusValue::newGood(),
                                [
-                                       AuthenticationResponse::newPass( $name ),
+                                       AuthenticationResponse::newPass( $userName ),
                                ],
                                $tmp = [
                                        AuthenticationResponse::newFail( $this->message( 'fail-in-secondary' ) ),
@@ -1212,7 +1210,7 @@ class AuthManagerTest extends \MediaWikiTestCase {
                        'Secondary UI, then abstain' => [
                                StatusValue::newGood(),
                                [
-                                       AuthenticationResponse::newPass( $name ),
+                                       AuthenticationResponse::newPass( $userName ),
                                ],
                                [
                                        $tmp = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
@@ -1220,19 +1218,19 @@ class AuthManagerTest extends \MediaWikiTestCase {
                                ],
                                [
                                        $tmp,
-                                       AuthenticationResponse::newPass( $name ),
+                                       AuthenticationResponse::newPass( $userName ),
                                ]
                        ],
                        'Secondary pass' => [
                                StatusValue::newGood(),
                                [
-                                       AuthenticationResponse::newPass( $name ),
+                                       AuthenticationResponse::newPass( $userName ),
                                ],
                                [
                                        AuthenticationResponse::newPass()
                                ],
                                [
-                                       AuthenticationResponse::newPass( $name ),
+                                       AuthenticationResponse::newPass( $userName ),
                                ]
                        ],
                ];