From: WMDE-Fisch Date: Thu, 1 Feb 2018 17:27:07 +0000 (+0100) Subject: Do not concat exception class name in Timestamp compat X-Git-Tag: 1.31.0-rc.0~716^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%22id_auteur=%24connect_id_auteur%22%29%20.%20%22?a=commitdiff_plain;h=64d7c7e6ec6323a9b65e25cc3d82de998fd6d1d6;p=lhc%2Fweb%2Fwiklou.git Do not concat exception class name in Timestamp compat It seems this is not necessary and confused my IDE in thinking 'Exception' is an alias for TimestampException. Given that we use a namespaced reference to the class, ClassCollector still won't see it. Updated test to verify that. Change-Id: I7c9258c5739a64959442af1296e2b93395260894 --- diff --git a/includes/compat/Timestamp.php b/includes/compat/Timestamp.php index bd254327e2..63b87ae12b 100644 --- a/includes/compat/Timestamp.php +++ b/includes/compat/Timestamp.php @@ -7,12 +7,12 @@ // loading context. This file will then register the alias and, as class_alias() does // by default, it will trigger a plain autoload for the destination class. -// The below uses string concatenation for the alias to avoid being seen by ClassCollector, -// which would insist on adding it to autoload.php, after which AutoLoaderTest will +// The below uses a namespaced class reference, to to avoid being seen by ClassCollector, +// which would otherwise add it to autoload.php, after which AutoLoaderTest will // complain about class_alias() not being in the target class file. /** * @deprecated since 1.29 * @since 1.20 */ -class_alias( Wikimedia\Timestamp\TimestampException::class, 'Timestamp' . 'Exception' ); +class_alias( Wikimedia\Timestamp\TimestampException::class, 'TimestampException' ); diff --git a/tests/phpunit/includes/utils/ClassCollectorTest.php b/tests/phpunit/includes/utils/ClassCollectorTest.php index 8e07b5efde..796d459a67 100644 --- a/tests/phpunit/includes/utils/ClassCollectorTest.php +++ b/tests/phpunit/includes/utils/ClassCollectorTest.php @@ -33,6 +33,12 @@ class ClassCollectorTest extends PHPUnit_Framework_TestCase { "class_alias( Foo::class, 'Bar' );", [ 'Bar' ], ], + [ + // Namespaced class is not currently supported. Must use namespace declaration + // earlier in the file. + "class_alias( Example\Foo::class, 'Bar' );", + [], + ], [ "namespace Example;\nclass Foo {}\nclass_alias( Foo::class, 'Bar' );", [ 'Example\Foo', 'Bar' ],