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

Commit

Permalink
Merge branch 'hotfix/service-listener-delegator'
Browse files Browse the repository at this point in the history
Close #41
  • Loading branch information
weierophinney committed Mar 30, 2016
2 parents 52467dd + 83d5cbf commit 563499c
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 38 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.1 - TBD
## 2.7.1 - 2016-03-30

### Added

- Nothing.
- [#41](https://github.com/zendframework/zend-i18n/pull/41) adds
`Zend\I18n\Module::init()`, which registers a specification for the translator
loader plugin manager with `Zend\ModuleManager\Listener\ServiceListener`.

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./test/bootstrap.php"
bootstrap="./vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="zend-i18n Test Suite">
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.travis
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./test/bootstrap.php"
bootstrap="./vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="zend-i18n Test Suite">
Expand Down
19 changes: 19 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,23 @@ public function getConfig()
'view_helpers' => $provider->getViewHelperConfig(),
];
}

/**
* Register a specification for the TranslatorPluginManager with the ServiceListener.
*
* @param \Zend\ModuleManager\ModuleEvent
* @return void
*/
public function init($event)
{
$container = $event->getParam('ServiceManager');
$serviceListener = $container->get('ServiceListener');

$serviceListener->addServiceManager(
'TranslatorPluginManager',
'translator_plugins',
'Zend\ModuleManager\Feature\TranslatorPluginProviderInterface',
'getTranslatorPluginConfig'
);
}
}
49 changes: 49 additions & 0 deletions test/ModuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @link http://github.com/zendframework/zend-i18n for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\I18n;

use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\I18n\Module;

class ModuleTest extends TestCase
{
public function setUp()
{
$this->module = new Module();
}

public function testConfigReturnsExpectedKeys()
{
$config = $this->module->getConfig();
$this->assertInternalType('array', $config);
$this->assertArrayHasKey('filters', $config);
$this->assertArrayHasKey('service_manager', $config);
$this->assertArrayHasKey('validators', $config);
$this->assertArrayHasKey('view_helpers', $config);
}

public function testInitRegistersPluginManagerSpecificationWithServiceListener()
{
$serviceListener = $this->prophesize(TestAsset\ServiceListenerInterface::class);
$serviceListener->addServiceManager(
'TranslatorPluginManager',
'translator_plugins',
'Zend\ModuleManager\Feature\TranslatorPluginProviderInterface',
'getTranslatorPluginConfig'
)->shouldBeCalled();

$container = $this->prophesize(ContainerInterface::class);
$container->get('ServiceListener')->willReturn($serviceListener->reveal());

$event = $this->prophesize(TestAsset\ModuleEventInterface::class);
$event->getParam('ServiceManager')->willReturn($container->reveal());

$this->assertNull($this->module->init($event->reveal()));
}
}
18 changes: 18 additions & 0 deletions test/TestAsset/ModuleEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @link http://github.com/zendframework/zend-i18n for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\I18n\TestAsset;

/**
* Mock interface to use when testing Module::init
*
* Mimics Zend\ModuleManager\ModuleEvent methods called.
*/
interface ModuleEventInterface
{
public function getParam($name, $default = null);
}
29 changes: 29 additions & 0 deletions test/TestAsset/ServiceListenerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link http://github.com/zendframework/zend-i18n for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\I18n\TestAsset;

/**
* Stub interfact to mock when testing Module::init.
*
* Mimics method that will be called on ServiceListener.
*/
interface ServiceListenerInterface
{
/**
* @param string $pluginManagerService
* @param string $configKey
* @param string $interface
* @param string $method
*/
public function addServiceManager(
$pluginManagerService,
$configKey,
$interface,
$method
);
}
34 changes: 0 additions & 34 deletions test/bootstrap.php

This file was deleted.

0 comments on commit 563499c

Please sign in to comment.