MediaWiki  REL1_31
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 }
DeprecatedGlobalTest\testLazyLoad
testLazyLoad()
Definition: DeprecatedGlobalTest.php:49
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
DeprecatedGlobalTest\testObjectDeStub
testObjectDeStub()
Definition: DeprecatedGlobalTest.php:36
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
DeprecatedGlobalTest\setUp
setUp()
Definition: DeprecatedGlobalTest.php:26
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWikiTestCase\$called
$called
$called tracks whether the setUp and tearDown method has been called.
Definition: MediaWikiTestCase.php:43
DeprecatedGlobalTest\testWarning
testWarning()
PHPUnit_Framework_Error Use of $wgDummy1 was deprecated in MediaWiki 1.30.
Definition: DeprecatedGlobalTest.php:73
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:1675
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
DeprecatedGlobalTest
DeprecatedGlobal.
Definition: DeprecatedGlobalTest.php:24
DeprecatedGlobal
Class to allow throwing wfDeprecated warnings when people use globals that we do not want them to.
Definition: DeprecatedGlobal.php:27
DeprecatedGlobalTest\tearDown
tearDown()
Definition: DeprecatedGlobalTest.php:31
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56