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

Commit

Permalink
Update TranslatorServiceFactory to pass empty array if no translator …
Browse files Browse the repository at this point in the history
…configuration present
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Translator/TranslatorServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function createService(ServiceLocatorInterface $serviceLocator)
{
// Configure the translator
$config = $serviceLocator->get('Configuration');
$translator = Translator::factory($config['translator']);
$trConfig = isset($config['translator']) ? $config['translator'] : array();
$translator = Translator::factory($trConfig);
return $translator;
}
}
30 changes: 30 additions & 0 deletions test/Translator/TranslatorServiceFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_I18n
*/

namespace ZendTest\I18n\Translator;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\I18n\Translator\TranslatorServiceFactory;

class TranslatorServiceFactoryTest extends TestCase
{
public function testCreateServiceWithNoTranslatorKeyDefined()
{
$slContents = array(array('Configuration', array()));
$serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface');
$serviceLocator->expects($this->once())
->method('get')
->will($this->returnValueMap($slContents));

$factory = new TranslatorServiceFactory();
$translator = $factory->createService($serviceLocator);
$this->assertInstanceOf('Zend\I18n\Translator\Translator', $translator);
}
}

0 comments on commit 2187ae2

Please sign in to comment.