Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Added test for locator-aware functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Nov 17, 2011
1 parent ec269f6 commit b452ee7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/PluginBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

namespace ZendTest\Loader;

use Zend\Loader\PluginBroker,
use stdClass,
Zend\Loader\PluginBroker,
Zend\Loader\PluginClassLoader;

/**
Expand Down Expand Up @@ -274,4 +275,18 @@ public function testAllowsConfigurationViaConstructor()
$loader = $broker->getClassLoader();
$this->assertInstanceOf('ZendTest\Loader\TestAsset\CustomClassLoader', $loader);
}

public function testWillPullFromLocatorIfAttached()
{
$locator = new TestAsset\ServiceLocator();
$plugin = new stdClass;
$locator->set('ZendTest\Loader\TestAsset\Foo', $plugin);

$loader = $this->broker->getClassLoader();
$loader->registerPlugin('foo', 'ZendTest\Loader\TestAsset\Foo');
$this->broker->setLocator($locator);

$test = $this->broker->load('foo');
$this->assertSame($plugin, $test);
}
}
24 changes: 24 additions & 0 deletions test/TestAsset/ServiceLocator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ZendTest\Loader\TestAsset;

use Zend\Di\Locator;

class ServiceLocator implements Locator
{
protected $services = array();

public function get($name, array $params = array())
{
if (!isset($this->services[$name])) {
return null;
}

return $this->services[$name];
}

public function set($name, $object)
{
$this->services[$name] = $object;
}
}

0 comments on commit b452ee7

Please sign in to comment.