Merge pull request #4482 from kinglozzer/classinfo-nonexistant-class

Ensure ClassInfo is backwards compatible with non-existant classes
This commit is contained in:
Sam Minnée 2015-08-10 15:45:32 +12:00
commit 5c3bf3d0a2
2 changed files with 16 additions and 0 deletions

View File

@ -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();

View File

@ -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);