diff options
author | Petr Pchelko <ppchelko@wikimedia.org> | 2021-08-04 11:45:27 -0700 |
---|---|---|
committer | Petr Pchelko <ppchelko@wikimedia.org> | 2021-08-04 12:38:02 -0700 |
commit | ac629eed2d7a18dfef48724aa99b7a043ad736a8 (patch) | |
tree | b699d04b58c4e7ec42ea85a6b211a5a9671d3e9b /includes/debug | |
parent | 81dd7da45f60ad23bbfe64babd2d9fa4b5e0bce7 (diff) | |
download | mediawikicore-ac629eed2d7a18dfef48724aa99b7a043ad736a8.tar.gz mediawikicore-ac629eed2d7a18dfef48724aa99b7a043ad736a8.zip |
DeprecationHelper: Support mocking and dynamic properties
DeprecationHelper currently breaks dynamic properties
on phpunit mocks. This happens because phpunit starts
mocking the magic methods if they're explicitly defined.
By default, magic methods and up doing nothing, but
if proxying to original methods is enabled, magic methods
are called like regular methods, regarless of whether
property exists or not. With this patch we can workaround
this issue, and create mocks for classes with deprecations.
Needed-By: I4297aea3489bb66c98c664da2332584c27793bfa
Change-Id: Id60a7751ece05669eced6eddd3216da7149411c7
Diffstat (limited to 'includes/debug')
-rw-r--r-- | includes/debug/DeprecationHelper.php | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/includes/debug/DeprecationHelper.php b/includes/debug/DeprecationHelper.php index 2e78535eac48..919dd2c59609 100644 --- a/includes/debug/DeprecationHelper.php +++ b/includes/debug/DeprecationHelper.php @@ -198,6 +198,12 @@ trait DeprecationHelper { if ( $ownerClass ) { // Someone tried to access a normal non-public property. Try to behave like PHP would. trigger_error( "Cannot access non-public property $qualifiedName", E_USER_ERROR ); + } elseif ( property_exists( $this, $name ) ) { + // Normally __get method will not be even called if the property exists, + // but in tests if we mock an object that uses DeprecationHelper, + // __get and __set magic methods will be mocked as well, and called + // regardless of the property existence. Support that use-case. + return $this->$name; } else { // Non-existing property. Try to behave like PHP would. trigger_error( "Undefined property: $qualifiedName", E_USER_NOTICE ); |