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

Commit

Permalink
Browse files Browse the repository at this point in the history
- re-flow conditionals, one condition per line; brace onto next line for
  multi-line conditionals.
- add comments where needed
- add imports where needed
  • Loading branch information
weierophinney committed May 6, 2013
1 parent c7910dd commit ba9be9e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
8 changes: 6 additions & 2 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,15 @@ protected function createServiceViaCallback($callable, $cName, $rName)
if (is_object($callable)) {
$factory = $callable;
} elseif (is_array($callable)) {
// reset both rewinds and returns the value of the first array element
$factory = reset($callable);
}

if (isset($factory) && ($factory instanceof MutableCreationOptionsInterface)
&& is_array($this->creationOptions) && !empty($this->creationOptions)){
if (isset($factory)
&& ($factory instanceof MutableCreationOptionsInterface)
&& is_array($this->creationOptions)
&& !empty($this->creationOptions)
) {
$factory->setCreationOptions($this->creationOptions);
}

Expand Down
24 changes: 14 additions & 10 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ZendTest\ServiceManager;

use ReflectionClass;
use ReflectionObject;
use Zend\ServiceManager\Exception;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Config;
Expand All @@ -31,11 +32,11 @@ public function setup()
$this->serviceManager = new ServiceManager;
$this->pluginManager = new FooPluginManager(new Config(array(
'factories' => array(
'Foo' => 'ZendTest\ServiceManager\TestAsset\FooFactory'
'Foo' => 'ZendTest\ServiceManager\TestAsset\FooFactory',
),
'shared' => array(
'Foo' => false
)
'Foo' => false,
),
)));
}

Expand Down Expand Up @@ -76,8 +77,8 @@ public function testAbstractFactoryWithMutableCreationOptions()
$mock = 'ZendTest\ServiceManager\TestAsset\AbstractFactoryWithMutableCreationOptions';
$abstractFactory = $this->getMock($mock, array('setCreationOptions'));
$abstractFactory->expects($this->once())
->method('setCreationOptions')
->with($creationOptions);
->method('setCreationOptions')
->with($creationOptions);

$this->pluginManager->addAbstractFactory($abstractFactory);
$instance = $this->pluginManager->get('classnoexists', $creationOptions);
Expand All @@ -89,9 +90,10 @@ public function testMutableMethodNeverCalledWithoutCreationOptions()
$mock = 'ZendTest\ServiceManager\TestAsset\CallableWithMutableCreationOptions';
$callable = $this->getMock($mock, array('setCreationOptions'));
$callable->expects($this->never())
->method('setCreationOptions');
->method('setCreationOptions');

$ref = new ReflectionObject($this->pluginManager);

$ref = new \ReflectionObject($this->pluginManager);
$method = $ref->getMethod('createServiceViaCallback');
$method->setAccessible(true);
$method->invoke($this->pluginManager, $callable, 'foo', 'bar');
Expand All @@ -103,13 +105,15 @@ public function testCallableObjectWithMutableCreationOptions()
$mock = 'ZendTest\ServiceManager\TestAsset\CallableWithMutableCreationOptions';
$callable = $this->getMock($mock, array('setCreationOptions'));
$callable->expects($this->once())
->method('setCreationOptions')
->with($creationOptions);
->method('setCreationOptions')
->with($creationOptions);

$ref = new ReflectionObject($this->pluginManager);

$ref = new \ReflectionObject($this->pluginManager);
$property = $ref->getProperty('creationOptions');
$property->setAccessible(true);
$property->setValue($this->pluginManager, $creationOptions);

$method = $ref->getMethod('createServiceViaCallback');
$method->setAccessible(true);
$method->invoke($this->pluginManager, $callable, 'foo', 'bar');
Expand Down
7 changes: 4 additions & 3 deletions test/TestAsset/AbstractFactoryWithMutableCreationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

namespace ZendTest\ServiceManager\TestAsset;

use Zend\ServiceManager\ServiceLocatorInterface;
use stdClass;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\MutableCreationOptionsInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* implements multiple interface mock
*
*/
class AbstractFactoryWithMutableCreationOptions implements
AbstractFactoryInterface,
Expand All @@ -27,7 +28,7 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator

public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return new \StdClass;
return new stdClass;
}

public function setCreationOptions(array $options)
Expand Down
7 changes: 4 additions & 3 deletions test/TestAsset/CallableWithMutableCreationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

namespace ZendTest\ServiceManager\TestAsset;

use Zend\ServiceManager\ServiceLocatorInterface;
use stdClass;
use Zend\ServiceManager\MutableCreationOptionsInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* implements multiple interface invokable object mock
*
*/
class CallableWithMutableCreationOptions implements MutableCreationOptionsInterface
{
Expand All @@ -24,6 +25,6 @@ public function setCreationOptions(array $options)

public function __invoke(ServiceLocatorInterface $serviceLocator, $cName, $rName)
{
return new \StdClass;
return new stdClass;
}
}

0 comments on commit ba9be9e

Please sign in to comment.