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

Add Module::init to register the TranslatorPluginManager with the ServiceListener #41

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.