wiki.techinc.nl/tests/phpunit/unit/includes/debug/DeprecatablePropertyArrayTest.php
Umherirrender 0099099bb0 tests: Change expectDeprecation to expectDeprecationAndContinue
TestCase::expectDeprecation() is deprecated in PHPUnit 10,
use mediawiki own MediaWikiTestCaseTrait::expectDeprecationAndContinue()
for this case. This avoids the trigger_error call and isolate the
deprecation check into MWDebug class.

The continue part is also helpful in StubGlobalUserTest, where after the
first deprecation access more code exists, that was not executed as
PhpUnit 9 converts deprecations to exceptions.
In RCFeedTest the exception needs to be catched as the code proceed
after the deprecation notice is emitted.

Bug: T342110
Change-Id: Iecf827bec0d5215fd21bbb20b84caf928ee108a0
2023-07-18 16:35:43 +00:00

81 lines
2.2 KiB
PHP

<?php
use MediaWiki\Debug\DeprecatablePropertyArray;
/**
* @covers \MediaWiki\Debug\DeprecatablePropertyArray
*/
class DeprecatablePropertyArrayTest extends MediaWikiUnitTestCase {
private const PROP_NAME = 'test_property';
/**
* @dataProvider provideDeprecationWarning
*/
public function testDeprecationWarning( callable $callback, string $message ) {
$this->expectDeprecationAndContinue( '/' . preg_quote( $message, '/' ) . '/' );
$callback();
}
public function provideDeprecationWarning() {
$propName = self::PROP_NAME;
$array = new DeprecatablePropertyArray(
[
self::PROP_NAME => 'test_value',
'callback' => static function () {
return 'callback_test_value';
},
],
[
self::PROP_NAME => 'DEPRECATED_VERSION',
'callback' => 'DEPRECATED_VERSION',
],
'TEST'
);
yield 'get' => [
function () use ( $array ) {
$this->assertSame( 'test_value', $array[ self::PROP_NAME ] );
},
"TEST get '{$propName}'"
];
yield 'get, callback' => [
function () use ( $array ) {
$this->assertSame( 'callback_test_value', $array[ 'callback' ] );
},
"TEST get 'callback'"
];
yield 'exists' => [
function () use ( $array ) {
$this->assertTrue( isset( $array[ self::PROP_NAME ] ) );
},
"TEST exists '{$propName}'"
];
yield 'unset' => [
static function () use ( $array ) {
unset( $array[ self::PROP_NAME ] );
},
"TEST unset '{$propName}'"
];
}
public function testNonDeprecated() {
$array = new DeprecatablePropertyArray( [], [], __METHOD__ );
$this->assertFalse( isset( $array[self::PROP_NAME] ) );
$array[self::PROP_NAME] = 'test_value';
$this->assertTrue( isset( $array[self::PROP_NAME] ) );
$this->assertSame( 'test_value', $array[self::PROP_NAME] );
unset( $array[self::PROP_NAME] );
$this->assertFalse( isset( $array[self::PROP_NAME] ) );
}
public function testNonDeprecatedNumerical() {
$array = new DeprecatablePropertyArray( [], [], __METHOD__ );
$this->assertFalse( isset( $array[0] ) );
$array[] = 'test_value';
$this->assertTrue( isset( $array[0] ) );
$this->assertSame( 'test_value', $array[0] );
unset( $array[0] );
$this->assertFalse( isset( $array[0] ) );
}
}