FIX: ClassManifest errors if files contain duplicate class names (fixes #3210)

This commit is contained in:
Loz Calver 2014-06-16 13:05:03 +01:00
parent 34304cf6e4
commit 3d71a22a98
5 changed files with 24 additions and 3 deletions

View File

@ -391,14 +391,15 @@ class SS_ClassManifest {
$extends = substr($extends, 1);
}
if (array_key_exists($name, $this->classes)) {
$lowercaseName = strtolower($name);
if (array_key_exists($lowercaseName, $this->classes)) {
throw new Exception(sprintf(
'There are two files containing the "%s" class: "%s" and "%s"',
$name, $this->classes[$name], $pathname
$name, $this->classes[$lowercaseName], $pathname
));
}
$this->classes[strtolower($name)] = $pathname;
$this->classes[$lowercaseName] = $pathname;
if ($extends) {
$extends = strtolower($extends);

View File

@ -126,4 +126,14 @@ class ClassManifestTest extends SapphireTest {
public function testManifestExcludeFilesPrefixedWithUnderscore() {
$this->assertNotContains('ignore', array_keys($this->manifest->getClasses()));
}
/**
* Assert that ClassManifest throws an exception when it encounters two files
* which contain classes with the same name
* @expectedException Exception
*/
public function testManifestWarnsAboutDuplicateClasses() {
$dummy = new SS_ClassManifest(dirname(__FILE__) . '/fixtures/classmanifest_duplicates', false, true, false);
}
}

View File

@ -0,0 +1,5 @@
<?php
/**
* @ignore
*/
class TESTClass { }

View File

@ -0,0 +1,5 @@
<?php
/**
* @ignore
*/
class testCLASS { }