Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit cde0d48

Browse files
committed
fixing class aliasing
1 parent 67746c2 commit cde0d48

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
.buildpath
1111
test/log
1212
vendor/
13-
.idea
13+
.idea

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<phpunit bootstrap="test/bootstrap.php" colors="true">
44
<testsuites>
55
<testsuite name="Project Test Suite">
6-
<directory>src/</directory>
6+
<directory>test/src/</directory>
77
</testsuite>
88
</testsuites>
99

@@ -17,7 +17,7 @@
1717

1818
<log
1919
type = "coverage-html"
20-
target = "./log/html"
20+
target = "test/log/html"
2121
charset = "UTF-8"
2222
yui = "true"
2323
hightlight = "true"

src/ArrayPath.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,18 @@ public static function exists($aSource, $mIndex)
172172
*
173173
* You can define your own alias if you want
174174
*
175+
* If a given class alias already exists it will not be registered
176+
*
177+
*
175178
* @param string $alias
179+
* @return boolean
176180
*/
177181
public static function registerClassAlias($alias = 'A')
178182
{
179-
class_alias('\MathiasGrimm\ArrayPath\ArrayPath', $alias);
183+
if (!class_exists($alias)) {
184+
return class_alias('\MathiasGrimm\ArrayPath\ArrayPath', $alias);
185+
}
186+
187+
return false;
180188
}
181189
}

test/src/ArrayPathTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,9 @@ public function testItRegisterClassAliasWithAlias()
217217
$this->assertTrue(MyAlias::exists($a, 'a/b/c'));
218218
}
219219

220+
public function testItRegisterAliasOnlyOnce()
221+
{
222+
$this->assertTrue(ArrayPath::registerClassAlias('AP'));
223+
$this->assertFalse(ArrayPath::registerClassAlias('AP'));
224+
}
220225
}

0 commit comments

Comments
 (0)