Skip to content

Commit

Permalink
Ensure ClassInfo is backwards compatible with non-existant classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer committed Aug 4, 2015
1 parent d0d34bd commit 687de33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/ClassInfo.php
Expand Up @@ -159,6 +159,13 @@ public static function subclassesFor($class) {
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();
Expand Down
9 changes: 9 additions & 0 deletions tests/core/ClassInfoTest.php
Expand Up @@ -42,6 +42,15 @@ public function testSubclassesFor() {
);
}

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);
Expand Down

0 comments on commit 687de33

Please sign in to comment.