3use Wikimedia\TestingAccessWrapper;
26 public function testGet( $propName, $expectedLevel, $expectedMessage ) {
27 if ( $expectedLevel ) {
29 $this->assertSame(
null, $this->testClass->$propName );
30 }, $expectedLevel, $expectedMessage );
33 $this->assertSame( 1, $this->testClass->$propName );
40 [
'protectedDeprecated',
null, null ],
41 [
'protectedNonDeprecated', E_USER_ERROR,
42 'Cannot access non-public property TestDeprecatedClass::$protectedNonDeprecated' ],
43 [
'privateDeprecated',
null, null ],
44 [
'privateNonDeprecated', E_USER_ERROR,
45 'Cannot access non-public property TestDeprecatedClass::$privateNonDeprecated' ],
46 [
'nonExistent', E_USER_NOTICE,
'Undefined property: TestDeprecatedClass::$nonExistent' ],
53 public function testSet( $propName, $expectedLevel, $expectedMessage ) {
55 if ( $expectedLevel ) {
57 $this->testClass->$propName = 0;
59 }, $expectedLevel, $expectedMessage );
61 if ( $propName ===
'nonExistent' ) {
62 $this->testClass->$propName = 0;
65 $this->testClass->$propName = 0;
74 [
'protectedDeprecated',
null, null ],
75 [
'protectedNonDeprecated', E_USER_ERROR,
76 'Cannot access non-public property TestDeprecatedClass::$protectedNonDeprecated' ],
77 [
'privateDeprecated',
null, null ],
78 [
'privateNonDeprecated', E_USER_ERROR,
79 'Cannot access non-public property TestDeprecatedClass::$privateNonDeprecated' ],
80 [
'nonExistent',
null, null ],
90 ], $this->testClass->getThings() );
94 $this->testClass->setThings( 2, 2, 2, 2 );
95 $wrapper = TestingAccessWrapper::newFromObject( $this->testClass );
96 $this->assertSame( 2, $wrapper->protectedDeprecated );
97 $this->assertSame( 2, $wrapper->protectedNonDeprecated );
98 $this->assertSame( 2, $wrapper->privateDeprecated );
99 $this->assertSame( 2, $wrapper->privateNonDeprecated );
104 $this->assertSame( 1, $this->testSubclass->getDeprecatedPrivateParentProperty() );
107 $this->testSubclass->setDeprecatedPrivateParentProperty( 0 );
109 $wrapper = TestingAccessWrapper::newFromObject( $this->testSubclass );
110 $this->assertSame( 0, $wrapper->privateDeprecated );
112 $fullName =
'TestDeprecatedClass::$privateNonDeprecated';
114 $this->assertSame(
null, $this->testSubclass->getNonDeprecatedPrivateParentProperty() );
115 }, E_USER_ERROR,
"Cannot access non-public property $fullName" );
117 $this->testSubclass->setNonDeprecatedPrivateParentProperty( 0 );
118 $wrapper = TestingAccessWrapper::newFromObject( $this->testSubclass );
119 $this->assertSame( 1, $wrapper->privateNonDeprecated );
120 }, E_USER_ERROR,
"Cannot access non-public property $fullName" );
124 $actualLevel = $actualMessage =
null;
125 set_error_handler(
function ( $errorCode, $errorStr ) use ( &$actualLevel, &$actualMessage ) {
126 $actualLevel = $errorCode;
127 $actualMessage = $errorStr;
130 restore_error_handler();
131 $this->assertSame( $level, $actualLevel );
132 $this->assertSame( $message, $actualMessage );
137 $this->assertSame( $expected, TestingAccessWrapper::newFromObject( $object )->$propName );
138 }
catch ( ReflectionException
$e ) {
139 if ( !preg_match(
"/Property (TestDeprecated(Class|Subclass)::)?$propName does not exist/",
145 if ( property_exists( $object, $propName ) ) {
146 $this->assertSame( $expected, $object->$propName );
154 $wrapper = TestingAccessWrapper::newFromClass( MWDebug::class );
155 $this->assertNotEmpty( $wrapper->deprecationWarnings );
testGet( $propName, $expectedLevel, $expectedMessage)
provideGet
assertErrorTriggered(callable $callback, $level, $message)
TestDeprecatedSubclass $testSubclass
assertDeprecationWarningIssued(callable $callback)
testSet( $propName, $expectedLevel, $expectedMessage)
provideSet
assertPropertySame( $expected, $object, $propName)
TestDeprecatedClass $testClass
returning false will NOT prevent logging $e