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

Commit

Permalink
Merge branch 'hotfix/151'
Browse files Browse the repository at this point in the history
Close #151
  • Loading branch information
weierophinney committed Jul 28, 2016
2 parents 222ae0b + 38ccac0 commit 9860eaf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#151](https://github.com/zfcampus/zf-hal/pull/151) updates the
`HalControllerPluginFactory` to work correctly under v2 releases of
zend-servicemanager.

## 1.4.1 - 2016-07-27

Expand Down
25 changes: 22 additions & 3 deletions src/Factory/HalControllerPluginFactory.php
Expand Up @@ -7,17 +7,36 @@
namespace ZF\Hal\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZF\Hal\Plugin\Hal;

class HalControllerPluginFactory
class HalControllerPluginFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return Hal
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$helpers = $container->get('ViewHelperManager');
$helpers = $container->get('ViewHelperManager');
return $helpers->get('Hal');
}

/**
* Create service
*
* @param ServiceLocatorInterface $container
* @return Hal
*/
public function createService(ServiceLocatorInterface $container)
{
if ($container instanceof AbstractPluginManager) {
$container = $container->getServiceLocator() ?: $container;
}
return $this($container, Hal::class);
}
}
27 changes: 26 additions & 1 deletion test/Factory/HalControllerPluginFactoryTest.php
Expand Up @@ -8,7 +8,6 @@

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Hydrator\HydratorPluginManager;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\ServiceManager;
use ZF\Hal\Factory\HalControllerPluginFactory;
use ZF\Hal\Plugin\Hal as HalPlugin;
Expand All @@ -33,4 +32,30 @@ public function testInstantiatesHalJsonRenderer()

$this->assertInstanceOf('ZF\Hal\Plugin\Hal', $plugin);
}

public function testInstantiatesHalJsonRendererWithV2()
{
$viewHelperManager = $this->getMockBuilder('Zend\View\HelperPluginManager')
->disableOriginalConstructor()
->getMock();
$viewHelperManager
->expects($this->once())
->method('get')
->will($this->returnValue(new HalPlugin(new HydratorPluginManager(new ServiceManager()))));

$services = new ServiceManager();
$services->setService('ViewHelperManager', $viewHelperManager);

$pluginManager = $this->getMockBuilder('Zend\ServiceManager\AbstractPluginManager')
->disableOriginalConstructor()
->getMock();
$pluginManager->expects($this->once())
->method('getServiceLocator')
->willReturn($services);

$factory = new HalControllerPluginFactory();
$plugin = $factory->createService($pluginManager);

$this->assertInstanceOf('ZF\Hal\Plugin\Hal', $plugin);
}
}

0 comments on commit 9860eaf

Please sign in to comment.