From 687de33d0d122c7cefef210bbd8fd7ccbd4c65d9 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Tue, 4 Aug 2015 14:05:15 +0100 Subject: [PATCH] Ensure ClassInfo is backwards compatible with non-existant classes --- core/ClassInfo.php | 7 +++++++ tests/core/ClassInfoTest.php | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/core/ClassInfo.php b/core/ClassInfo.php index 71681f362..ac04c2508 100644 --- a/core/ClassInfo.php +++ b/core/ClassInfo.php @@ -159,6 +159,13 @@ class ClassInfo { public static function class_name($nameOrObject) { if (is_object($nameOrObject)) { return get_class($nameOrObject); + } elseif (!self::exists($nameOrObject)) { + Deprecation::notice( + '4.0', + "ClassInfo::class_name() passed a class that doesn't exist. Support for this will be removed in 4.0", + Deprecation::SCOPE_GLOBAL + ); + return $nameOrObject; } $reflection = new ReflectionClass($nameOrObject); return $reflection->getName(); diff --git a/tests/core/ClassInfoTest.php b/tests/core/ClassInfoTest.php index cc6952b7d..84c2e59f2 100644 --- a/tests/core/ClassInfoTest.php +++ b/tests/core/ClassInfoTest.php @@ -42,6 +42,15 @@ class ClassInfoTest extends SapphireTest { ); } + public function testClassName() { + $this->assertEquals('ClassInfoTest', ClassInfo::class_name($this)); + $this->assertEquals('ClassInfoTest', ClassInfo::class_name('ClassInfoTest')); + $this->assertEquals('ClassInfoTest', ClassInfo::class_name('CLaSsInfOTEsT')); + + // This is for backwards compatiblity and will be removed in 4.0 + $this->assertEquals('IAmAClassThatDoesNotExist', ClassInfo::class_name('IAmAClassThatDoesNotExist')); + } + public function testClassesForFolder() { //$baseFolder = Director::baseFolder() . '/' . FRAMEWORK_DIR . '/tests/_ClassInfoTest'; //$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);