Add tablesUsed to RevisionStoreDbTest
[lhc/web/wiklou.git] / tests / phpunit / includes / DeprecatedGlobalTest.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 /**
22 * @covers DeprecatedGlobal
23 */
24 class DeprecatedGlobalTest extends MediaWikiTestCase {
25
26 public function setUp() {
27 parent::setUp();
28 $this->oldErrorLevel = error_reporting( -1 );
29 }
30
31 public function tearDown() {
32 error_reporting( $this->oldErrorLevel );
33 parent::tearDown();
34 }
35
36 public function testObjectDeStub() {
37 global $wgDummy;
38
39 $wgDummy = new DeprecatedGlobal( 'wgDummy', new HashBagOStuff(), '1.30' );
40 $this->assertInstanceOf( DeprecatedGlobal::class, $wgDummy );
41
42 $this->hideDeprecated( '$wgDummy' );
43 // Trigger de-stubification
44 $wgDummy->get( 'foo' );
45
46 $this->assertInstanceOf( HashBagOStuff::class, $wgDummy );
47 }
48
49 public function testLazyLoad() {
50 global $wgDummyLazy;
51
52 $called = false;
53 $factory = function () use ( &$called ) {
54 $called = true;
55 return new HashBagOStuff();
56 };
57
58 $wgDummyLazy = new DeprecatedGlobal( 'wgDummyLazy', $factory, '1.30' );
59 $this->assertInstanceOf( DeprecatedGlobal::class, $wgDummyLazy );
60
61 $this->hideDeprecated( '$wgDummyLazy' );
62 $this->assertFalse( $called );
63 // Trigger de-stubification
64 $wgDummyLazy->get( 'foo' );
65 $this->assertTrue( $called );
66 $this->assertInstanceOf( HashBagOStuff::class, $wgDummyLazy );
67 }
68
69 /**
70 * @expectedException PHPUnit_Framework_Error
71 * @expectedExceptionMessage Use of $wgDummy1 was deprecated in MediaWiki 1.30
72 */
73 public function testWarning() {
74 global $wgDummy1;
75
76 $wgDummy1 = new DeprecatedGlobal( 'wgDummy1', new HashBagOStuff(), '1.30' );
77 $wgDummy1->get( 'foo' );
78 $this->assertInstanceOf( HashBagOStuff::class, $wgDummy1 );
79 }
80
81 }