| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\StubObject\DeprecatedGlobal; |
| 22 |
use Wikimedia\ObjectCache\HashBagOStuff; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class DeprecatedGlobalTest extends MediaWikiUnitTestCase { |
| 28 |
|
| 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 |
|
| 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 |
|
| 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 |
} |