From 3d71a22a9806643590ba4dd03fd88251de855f59 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Mon, 16 Jun 2014 13:05:03 +0100 Subject: [PATCH] FIX: ClassManifest errors if files contain duplicate class names (fixes #3210) --- core/manifest/ClassManifest.php | 7 ++++--- tests/core/manifest/ClassManifestTest.php | 10 ++++++++++ .../classmanifest_duplicates/module/_config.php | 0 .../module/classes/TestClassA.php | 5 +++++ .../module/classes/TestClassB.php | 5 +++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/core/manifest/fixtures/classmanifest_duplicates/module/_config.php create mode 100644 tests/core/manifest/fixtures/classmanifest_duplicates/module/classes/TestClassA.php create mode 100644 tests/core/manifest/fixtures/classmanifest_duplicates/module/classes/TestClassB.php diff --git a/core/manifest/ClassManifest.php b/core/manifest/ClassManifest.php index 042871f21..071d0aae3 100644 --- a/core/manifest/ClassManifest.php +++ b/core/manifest/ClassManifest.php @@ -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); diff --git a/tests/core/manifest/ClassManifestTest.php b/tests/core/manifest/ClassManifestTest.php index fa82e8d12..0a0e7ddc9 100644 --- a/tests/core/manifest/ClassManifestTest.php +++ b/tests/core/manifest/ClassManifestTest.php @@ -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); + } + } diff --git a/tests/core/manifest/fixtures/classmanifest_duplicates/module/_config.php b/tests/core/manifest/fixtures/classmanifest_duplicates/module/_config.php new file mode 100644 index 000000000..e69de29bb diff --git a/tests/core/manifest/fixtures/classmanifest_duplicates/module/classes/TestClassA.php b/tests/core/manifest/fixtures/classmanifest_duplicates/module/classes/TestClassA.php new file mode 100644 index 000000000..8ed30aceb --- /dev/null +++ b/tests/core/manifest/fixtures/classmanifest_duplicates/module/classes/TestClassA.php @@ -0,0 +1,5 @@ +