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.
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.
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
22 * @covers DeprecatedGlobal
24 class DeprecatedGlobalTest
extends MediaWikiTestCase
{
26 public function setUp() {
28 $this->oldErrorLevel
= error_reporting( -1 );
31 public function tearDown() {
32 error_reporting( $this->oldErrorLevel
);
36 public function testObjectDeStub() {
39 $wgDummy = new DeprecatedGlobal( 'wgDummy', new HashBagOStuff(), '1.30' );
40 $this->assertInstanceOf( DeprecatedGlobal
::class, $wgDummy );
42 $this->hideDeprecated( '$wgDummy' );
43 // Trigger de-stubification
44 $wgDummy->get( 'foo' );
46 $this->assertInstanceOf( HashBagOStuff
::class, $wgDummy );
49 public function testLazyLoad() {
53 $factory = function () use ( &$called ) {
55 return new HashBagOStuff();
58 $wgDummyLazy = new DeprecatedGlobal( 'wgDummyLazy', $factory, '1.30' );
59 $this->assertInstanceOf( DeprecatedGlobal
::class, $wgDummyLazy );
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 );
70 * @expectedException PHPUnit_Framework_Error
71 * @expectedExceptionMessage Use of $wgDummy1 was deprecated in MediaWiki 1.30
73 public function testWarning() {
76 $wgDummy1 = new DeprecatedGlobal( 'wgDummy1', new HashBagOStuff(), '1.30' );
77 $wgDummy1->get( 'foo' );
78 $this->assertInstanceOf( HashBagOStuff
::class, $wgDummy1 );