MediaWiki REL1_30
DeprecatedGlobalTest.php
Go to the documentation of this file.
1<?php
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
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}
testWarning()
PHPUnit_Framework_Error Use of $wgDummy1 was deprecated in MediaWiki 1.30.
Class to allow throwing wfDeprecated warnings when people use globals that we do not want them to.
Simple store for keeping values in an associative array for the current process.
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
$called
$called tracks whether the setUp and tearDown method has been called.