X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdebug%2FDeprecationHelperTest.php;h=25dedbc2b0e13607e21f228084fc7416b9f745ea;hp=6b977a3eaf0b6e0d27ec88e441e109c104e20644;hb=6cfb2e3d7a2b96d5041312fcec88248bb46573d7;hpb=a4120368bb7797df25004613feed9406eac1c9d0 diff --git a/tests/phpunit/includes/debug/DeprecationHelperTest.php b/tests/phpunit/includes/debug/DeprecationHelperTest.php index 6b977a3eaf..25dedbc2b0 100644 --- a/tests/phpunit/includes/debug/DeprecationHelperTest.php +++ b/tests/phpunit/includes/debug/DeprecationHelperTest.php @@ -37,10 +37,8 @@ class DeprecationHelperTest extends MediaWikiTestCase { public function provideGet() { return [ - [ 'protectedDeprecated', null, null ], [ 'protectedNonDeprecated', E_USER_ERROR, 'Cannot access non-public property TestDeprecatedClass::$protectedNonDeprecated' ], - [ 'privateDeprecated', null, null ], [ 'privateNonDeprecated', E_USER_ERROR, 'Cannot access non-public property TestDeprecatedClass::$privateNonDeprecated' ], [ 'nonExistent', E_USER_NOTICE, 'Undefined property: TestDeprecatedClass::$nonExistent' ], @@ -71,10 +69,8 @@ class DeprecationHelperTest extends MediaWikiTestCase { public function provideSet() { return [ - [ 'protectedDeprecated', null, null ], [ 'protectedNonDeprecated', E_USER_ERROR, 'Cannot access non-public property TestDeprecatedClass::$protectedNonDeprecated' ], - [ 'privateDeprecated', null, null ], [ 'privateNonDeprecated', E_USER_ERROR, 'Cannot access non-public property TestDeprecatedClass::$privateNonDeprecated' ], [ 'nonExistent', null, null ], @@ -100,15 +96,6 @@ class DeprecationHelperTest extends MediaWikiTestCase { } public function testSubclassGetSet() { - $this->assertDeprecationWarningIssued( function () { - $this->assertSame( 1, $this->testSubclass->getDeprecatedPrivateParentProperty() ); - } ); - $this->assertDeprecationWarningIssued( function () { - $this->testSubclass->setDeprecatedPrivateParentProperty( 0 ); - } ); - $wrapper = TestingAccessWrapper::newFromObject( $this->testSubclass ); - $this->assertSame( 0, $wrapper->privateDeprecated ); - $fullName = 'TestDeprecatedClass::$privateNonDeprecated'; $this->assertErrorTriggered( function () { $this->assertSame( null, $this->testSubclass->getNonDeprecatedPrivateParentProperty() ); @@ -118,6 +105,16 @@ class DeprecationHelperTest extends MediaWikiTestCase { $wrapper = TestingAccessWrapper::newFromObject( $this->testSubclass ); $this->assertSame( 1, $wrapper->privateNonDeprecated ); }, E_USER_ERROR, "Cannot access non-public property $fullName" ); + + $fullName = 'TestDeprecatedSubclass::$subclassPrivateNondeprecated'; + $this->assertErrorTriggered( function () { + $this->assertSame( null, $this->testSubclass->subclassPrivateNondeprecated ); + }, E_USER_ERROR, "Cannot access non-public property $fullName" ); + $this->assertErrorTriggered( function () { + $this->testSubclass->subclassPrivateNondeprecated = 0; + $wrapper = TestingAccessWrapper::newFromObject( $this->testSubclass ); + $this->assertSame( 1, $wrapper->subclassPrivateNondeprecated ); + }, E_USER_ERROR, "Cannot access non-public property $fullName" ); } protected function assertErrorTriggered( callable $callback, $level, $message ) { @@ -155,4 +152,22 @@ class DeprecationHelperTest extends MediaWikiTestCase { $this->assertNotEmpty( $wrapper->deprecationWarnings ); } + /** + * Test bad MW version values to throw exceptions as expected + * + * @dataProvider provideBadMWVersion + */ + public function testBadMWVersion( $version, $expected ) { + $this->setExpectedException( $expected ); + + wfDeprecated( __METHOD__, $version ); + } + + public function provideBadMWVersion() { + return [ + [ 1, Exception::class ], + [ 1.33, Exception::class ], + [ null, Exception::class ] + ]; + } }