Permalink
Browse files

Further improvements to the aliasing.

  • Loading branch information...
1 parent 3591de1 commit 67144d724ea1f45ff2534f047da9a66523fb8b93 @trq trq committed Feb 7, 2013
Showing with 36 additions and 0 deletions.
  1. +4 −0 lib/Proem/Service/AssetManager.php
  2. +32 −0 lib/Proem/Service/Tests/AssetManagerTest.php
@@ -76,6 +76,10 @@ public function alias($type, $alias = null, $override = false)
foreach ($type as $alias => $asset) {
$this->setParam('aliases', $alias, $asset, $override);
}
+ } else if (is_array($alias)) {
+ foreach ($alias as $a) {
+ $this->setParam('aliases', $a, $type, $override);
+ }
} else {
$this->setParam('aliases', $alias, $type, $override);
}
@@ -122,6 +122,15 @@ public function testSingleton()
$this->assertSame($am->resolve('stdClass'), $am->resolve('stdClass'));
}
+ public function testCanAliasAndResolveSingletonWithoutResolver()
+ {
+ $am = new AssetManager;
+ $am->singleton(['sClass' => '\stdClass']);
+
+ $this->assertInstanceOf('\stdClass', $am->resolve('sClass'));
+ $this->assertSame($am->resolve('sClass'), $am->resolve('sClass'));
+ }
+
public function testCanAlias()
{
$am = new AssetManager;
@@ -142,6 +151,16 @@ public function testCanAliasViaArray()
$this->assertInstanceOf('\stdClass', $am->resolve('stdClass'));
}
+ public function testCanAliasSingeToMultiple()
+ {
+ $am = new AssetManager;
+ $am->alias('stdClass', ['foo', 'bar', 'bob']);
+
+ $this->assertInstanceOf('\stdClass', $am->resolve('foo'));
+ $this->assertInstanceOf('\stdClass', $am->resolve('bar'));
+ $this->assertInstanceOf('\stdClass', $am->resolve('bob'));
+ }
+
public function testComplexAlias()
{
$am = new AssetManager;
@@ -158,6 +177,19 @@ public function testComplexAliasWithSingleton()
$am->alias([
'abcObjectInterface' => 'abcObject',
'abcAlias' => 'abcObjectInterface'
+ ])->singleton('abcObjectInterface', '\stdClass');
+
+ $this->assertInstanceOf('\stdClass', $am->resolve('abcAlias'));
+ $this->assertSame($am->resolve('abcAlias'), $am->resolve('abcAlias'));
+ $this->assertSame($am->resolve('abcAlias'), $am->resolve('abcObjectInterface'));
+ }
+
+ public function testComplexAliasWithSingletonVerbose()
+ {
+ $am = new AssetManager;
+ $am->alias([
+ 'abcObjectInterface' => 'abcObject',
+ 'abcAlias' => 'abcObjectInterface'
])->attach('abcObjectInterface', function() { return new \stdClass; }, true);
$this->assertInstanceOf('\stdClass', $am->resolve('abcAlias'));

0 comments on commit 67144d7

Please sign in to comment.