Debian Codegraph @

tests/phpunit/unit/includes/StubObject/DeprecatedGlobalTest.php

raw symbols SCIP
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 use MediaWiki\StubObject\DeprecatedGlobal;
22 use Wikimedia\ObjectCache\HashBagOStuff;
23
24 /**
25 * @covers \MediaWiki\StubObject\DeprecatedGlobal
26 */
27 class DeprecatedGlobalTest extends MediaWikiUnitTestCase {
28 /** @var int */
29 private $oldErrorLevel;
30
31 protected function setUp(): void {
32 parent::setUp();
33 $this->oldErrorLevel = error_reporting( -1 );
34 }
35
36 protected function tearDown(): void {
37 error_reporting( $this->oldErrorLevel );
38 parent::tearDown();
39 }
40
41 public function testObjectDeStub() {
42 global $wgDummy;
43
44 $wgDummy = new DeprecatedGlobal( 'wgDummy', new HashBagOStuff(), '1.30' );
45 $this->assertInstanceOf( DeprecatedGlobal::class, $wgDummy );
46
47 $this->hideDeprecated( '$wgDummy' );
48 // Trigger de-stubification
49 $wgDummy->get( 'foo' );
50
51 $this->assertInstanceOf( HashBagOStuff::class, $wgDummy );
52 }
53
54 public function testLazyLoad() {
55 global $wgDummyLazy;
56
57 $called = false;
58 $factory = static function () use ( &$called ) {
59 $called = true;
60 return new HashBagOStuff();
61 };
62
63 $wgDummyLazy = new DeprecatedGlobal( 'wgDummyLazy', $factory, '1.30' );
64 $this->assertInstanceOf( DeprecatedGlobal::class, $wgDummyLazy );
65
66 $this->hideDeprecated( '$wgDummyLazy' );
67 $this->assertFalse( $called );
68 // Trigger de-stubification
69 $wgDummyLazy->get( 'foo' );
70 $this->assertTrue( $called );
71 $this->assertInstanceOf( HashBagOStuff::class, $wgDummyLazy );
72 }
73
74 public function testWarning() {
75 global $wgDummy1;
76
77 $wgDummy1 = new DeprecatedGlobal( 'wgDummy1', new HashBagOStuff(), '1.30' );
78 $this->expectDeprecationAndContinue( '/Use of \$wgDummy1 was deprecated in MediaWiki 1\.30/' );
79 $wgDummy1->get( 'foo' );
80 $this->assertInstanceOf( HashBagOStuff::class, $wgDummy1 );
81 }
82
83 }