3 * Holds tests for LBFactory abstract MediaWiki class.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 * @author Antoine Musso
23 * @copyright © 2013 Antoine Musso
24 * @copyright © 2013 Wikimedia Foundation Inc.
27 class FakeLBFactory
extends LBFactory
{
28 function __construct( $conf ) {}
29 function newMainLB( $wiki = false ) {}
30 function getMainLB( $wiki = false ) {}
31 function newExternalLB( $cluster, $wiki = false ) {}
32 function &getExternalLB( $cluster, $wiki = false ) {}
33 function forEachLB( $callback, $params = array() ) {}
36 class LBFactoryTest
extends MediaWikiTestCase
{
40 FakeLBFactory
::destroyInstance();
44 * @dataProvider provideDeprecatedLbfactoryClasses
46 function testLbfactoryClassBackcompatibility( $expected, $deprecated ) {
47 $mockDB = $this->getMockBuilder( 'DatabaseMysql' )
48 -> disableOriginalConstructor()
50 $this->setMwGlobals( 'wgLBFactoryConf',
52 'class' => $deprecated,
53 'connection' => $mockDB,
54 # Various other parameters required:
55 'sectionsByDB' => array(),
56 'sectionLoads' => array(),
57 'serverTemplate' => array(),
61 global $wgLBFactoryConf;
62 $this->assertArrayHasKey( 'class', $wgLBFactoryConf );
63 $this->assertEquals( $wgLBFactoryConf['class'], $deprecated );
65 # The point of this test is to call a deprecated interface and make
66 # sure it keeps back compatibility, so skip the deprecation warning.
67 $this->hideDeprecated( '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details' );
68 $lbfactory = FakeLBFactory
::singleton();
69 $this->assertInstanceOf( $expected, $lbfactory,
70 "LBFactory passed $deprecated should yield the new class $expected" );
73 function provideDeprecatedLbfactoryClasses() {
75 # Format: new class, old class
76 array( 'LBFactorySimple', 'LBFactory_Simple' ),
77 array( 'LBFactorySingle', 'LBFactory_Single' ),
78 array( 'LBFactoryMulti', 'LBFactory_Multi' ),
79 array( 'LBFactoryFake', 'LBFactory_Fake' ),