diff --git a/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/DoctrineLoader.php b/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/DoctrineLoader.php index a27e97c..207bdda 100644 --- a/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/DoctrineLoader.php +++ b/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/DoctrineLoader.php @@ -28,7 +28,7 @@ public function __construct(EntityManager $entityManager) /** * @param string $locale * @param string $domain - * @return null|TextDomain + * @return TextDomain * @throws \BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException */ public function load($locale, $domain) diff --git a/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/Factory/DoctrineLoaderFactory.php b/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/Factory/DoctrineLoaderFactory.php index 94ef63a..c5b1070 100644 --- a/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/Factory/DoctrineLoaderFactory.php +++ b/src/BsbDoctrineTranslationLoader/I18n/Translator/Loader/Factory/DoctrineLoaderFactory.php @@ -10,8 +10,6 @@ class DoctrineLoaderFactory implements FactoryInterface { /** * {@inheritdocs} - * - * @todo make EntityManager configurable */ public function createService(ServiceLocatorInterface $serviceLocator) { diff --git a/src/BsbDoctrineTranslationLoader/Service/MvcTranslatorDelegatorFactory.php b/src/BsbDoctrineTranslationLoader/Service/MvcTranslatorDelegatorFactory.php index 7e57529..5e17fc1 100644 --- a/src/BsbDoctrineTranslationLoader/Service/MvcTranslatorDelegatorFactory.php +++ b/src/BsbDoctrineTranslationLoader/Service/MvcTranslatorDelegatorFactory.php @@ -3,7 +3,7 @@ namespace BsbDoctrineTranslationLoader\Service; use Zend\I18n\Translator\LoaderPluginManager; -use Zend\Mvc\I18n\Translator; +use Zend\I18n\Translator\Translator; use Zend\ServiceManager\Config; use Zend\ServiceManager\DelegatorFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -13,7 +13,7 @@ class MvcTranslatorDelegatorFactory implements DelegatorFactoryInterface protected $translator_config = array( 'factories' => array( 'BsbDoctrineTranslationLoader' - => 'BsbDoctrineTranslationLoader\I18n\Translator\Loader\Factory\DoctrineLoaderFactory', + => 'BsbDoctrineTranslationLoader\I18n\Translator\Loader\Factory\DoctrineLoaderFactory', ), ); diff --git a/src/BsbDoctrineTranslationLoader/Util/ConfigManipulate.php b/src/BsbDoctrineTranslationLoader/Util/ConfigManipulate.php index fc4ded3..a39f1fb 100644 --- a/src/BsbDoctrineTranslationLoader/Util/ConfigManipulate.php +++ b/src/BsbDoctrineTranslationLoader/Util/ConfigManipulate.php @@ -7,7 +7,9 @@ class ConfigManipulate { - + /** + * Token used as key in configuration 'template' to replace EntityManager 'name' + */ const EM_REPLACE_TOKEN = '__em_token__'; public static function onMergeConfig(ModuleEvent $e) diff --git a/test/BsbDoctrineTranslationLoaderTest/Entity/LocaleTest.php b/test/BsbDoctrineTranslationLoaderTest/Entity/LocaleTest.php index b067b59..f290b26 100644 --- a/test/BsbDoctrineTranslationLoaderTest/Entity/LocaleTest.php +++ b/test/BsbDoctrineTranslationLoaderTest/Entity/LocaleTest.php @@ -3,8 +3,6 @@ namespace BsbDoctrineTranslationLoaderTest\I18n\Translator\Loader; use BsbDoctrineTranslationLoader\Entity\Locale; -use BsbDoctrineTranslationLoader\I18n\Translator\Loader\Doctrine; -use BsbDoctrineTranslationLoader\I18n\Translator\Loader\DoctrineLoader; use BsbDoctrineTranslationLoaderTest\Framework\TestCase; class LocaleTest extends TestCase @@ -38,4 +36,4 @@ public function testAccessorsPluralForms() $this->assertEquals($expected, $locale->getPluralForms()); } -} \ No newline at end of file +} diff --git a/test/BsbDoctrineTranslationLoaderTest/Entity/MessageTest.php b/test/BsbDoctrineTranslationLoaderTest/Entity/MessageTest.php index 8a3ca17..dcdf261 100644 --- a/test/BsbDoctrineTranslationLoaderTest/Entity/MessageTest.php +++ b/test/BsbDoctrineTranslationLoaderTest/Entity/MessageTest.php @@ -2,7 +2,6 @@ namespace BsbDoctrineTranslationLoaderTest\I18n\Translator\Loader; -use BsbDoctrineTranslationLoader\Entity\Locale; use BsbDoctrineTranslationLoader\Entity\Message; use BsbDoctrineTranslationLoaderTest\Framework\TestCase; @@ -62,5 +61,4 @@ public function testAccessorsTranslation() $message->setTranslation($expected); $this->assertEquals($expected, $message->getTranslation()); } - -} \ No newline at end of file +} diff --git a/test/BsbDoctrineTranslationLoaderTest/Framework/TestCase.php b/test/BsbDoctrineTranslationLoaderTest/Framework/TestCase.php index ac4d408..bdee356 100644 --- a/test/BsbDoctrineTranslationLoaderTest/Framework/TestCase.php +++ b/test/BsbDoctrineTranslationLoaderTest/Framework/TestCase.php @@ -1,21 +1,4 @@ . - */ namespace BsbDoctrineTranslationLoaderTest\Framework; @@ -51,7 +34,7 @@ public function createDb() $tool = new SchemaTool($em); $createSql = $tool->getCreateSchemaSql($meta); - foreach($createSql as $sql) { + foreach ($createSql as $sql) { $conn->executeQuery($sql); } diff --git a/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderFunctionalTest.php b/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderFunctionalTest.php index 5ede04a..7c4ebf8 100644 --- a/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderFunctionalTest.php +++ b/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderFunctionalTest.php @@ -6,11 +6,7 @@ use BsbDoctrineTranslationLoader\Entity\Message; use BsbDoctrineTranslationLoader\I18n\Translator\Loader\DoctrineLoader; use BsbDoctrineTranslationLoaderTest\Framework\TestCase; -use BsbDoctrineTranslationLoaderTest\Util\ServiceManagerFactory; -use BsbDoctrineTranslationLoader\I18n\Translator\Loader\Doctrine; -use Doctrine\ORM\Tools\SchemaTool; use Zend\I18n\Translator\TextDomain; -use Zend\ServiceManager\ServiceManager; class DoctrineLoaderFunctionalTest extends TestCase { @@ -36,7 +32,8 @@ public function tearDown() unset($this->doctrineLoader); } - protected function addLocale($locale, $pluralForm = 'nplurals=2; plural=n != 1;') { + protected function addLocale($locale, $pluralForm = 'nplurals=2; plural=n != 1;') + { $entity = new Locale(); $entity->setLocale($locale); $entity->setPluralForms($pluralForm); @@ -46,9 +43,12 @@ protected function addLocale($locale, $pluralForm = 'nplurals=2; plural=n != 1;' return $entity; } - protected function addMessage($locale, $message, $translation, $pluralIndex = null, $domain = 'default') { + protected function addMessage($locale, $message, $translation, $pluralIndex = null, $domain = 'default') + { if (is_string($locale)) { - $localeEntity = $this->getEntityManager()->getRepository('BsbDoctrineTranslationLoader\Entity\Locale')->findOneBy(array('locale'=>$locale)); + $localeEntity = $this->getEntityManager() + ->getRepository('BsbDoctrineTranslationLoader\Entity\Locale') + ->findOneBy(array('locale'=>$locale)); } else { $localeEntity = $locale; } @@ -66,7 +66,7 @@ protected function addMessage($locale, $message, $translation, $pluralIndex = nu return $message; } - public function test_SingularLoad() + public function testSingularLoad() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, 'key', 'sleutel'); @@ -83,7 +83,7 @@ public function test_SingularLoad() $this->assertEquals($textDomain['key'], 'key'); } - public function test_PluralLoad() + public function testPluralLoad() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, '%s key', '%s sleutels', 0); @@ -110,30 +110,34 @@ public function test_PluralLoad() $this->assertEquals($textDomain['%s key'][1], '%s key'); } - public function test_incorrectPluralRuleThrowsException() + public function testIncorrectPluralRuleThrowsException() { $locale = $this->addLocale('nl_NL', 'incorrect plural rule'); - $this->setExpectedException('BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', - 'Incorrect plural rule detected for locale'); + $this->setExpectedException( + 'BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', + 'Incorrect plural rule detected for locale' + ); /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); } - public function test_duplicateLocaleThrowsException() + public function testDuplicateLocaleThrowsException() { $locale = $this->addLocale('nl_NL'); $locale = $this->addLocale('nl_NL'); - $this->setExpectedException('BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', - 'Duplicate locale entry detected'); + $this->setExpectedException( + 'BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', + 'Duplicate locale entry detected' + ); /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); } - public function test_unknownLocaleReturnsEmptyTextDomain() + public function testUnknownLocaleReturnsEmptyTextDomain() { /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); @@ -142,7 +146,7 @@ public function test_unknownLocaleReturnsEmptyTextDomain() $this->assertCount(0, $textDomain); } - public function test_unknownDomainReturnsEmptyTextDomain() + public function testUnknownDomainReturnsEmptyTextDomain() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, 'key', 'sleutel'); @@ -155,55 +159,63 @@ public function test_unknownDomainReturnsEmptyTextDomain() $this->assertCount(0, $textDomain); } - public function test_duplicateSingularMessageThrowsException() + public function testDuplicateSingularMessageThrowsException() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, 'key', 'sleutel'); $this->addMessage($locale, 'key', 'sleutel'); - $this->setExpectedException('BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', - 'Singular entries must be have unique keys from both singular and plural forms'); + $this->setExpectedException( + 'BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', + 'Singular entries must be have unique keys from both singular and plural forms' + ); /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); } - public function test_identicalSingularAndPluralMessageThrowsException() + public function testIdenticalSingularAndPluralMessageThrowsException() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, 'key', 'sleutel'); $this->addMessage($locale, 'key', 'sleutel', 1); - $this->setExpectedException('BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', - 'Plural entries must be have unique keys from singular forms'); + $this->setExpectedException( + 'BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', + 'Plural entries must be have unique keys from singular forms' + ); /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); } - public function test_IdenticalPluralAndSingularMessageThrowsException() + public function testIdenticalPluralAndSingularMessageThrowsException() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, 'key', 'sleutel', 1); $this->addMessage($locale, 'key', 'sleutel'); - $this->setExpectedException('BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', - 'Singular entries must be have unique keys from both singular and plural forms'); + $this->setExpectedException( + 'BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', + 'Singular entries must be have unique keys from both singular and plural forms' + ); /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); } - public function test_duplicatePluralIndexThrowsException() + public function testDuplicatePluralIndexThrowsException() { $locale = $this->addLocale('nl_NL'); $this->addMessage($locale, '%s key', 'sleutels', 1); $this->addMessage($locale, '%s key', 'sleutel', 1); - $this->setExpectedException('BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', - 'Duplicate plural entry detected'); + $this->setExpectedException( + 'BsbDoctrineTranslationLoader\I18n\Exception\InvalidArgumentException', + 'Duplicate plural entry detected' + ); /** @var TextDomain $textDomain */ $textDomain = $this->doctrineLoader->load('nl_NL', 'default'); } -} \ No newline at end of file +} diff --git a/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderTest.php b/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderTest.php index ea26e0a..7ac1d29 100644 --- a/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderTest.php +++ b/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/DoctrineLoaderTest.php @@ -18,4 +18,4 @@ public function testInstanceOf() $this->assertInstanceOf('Zend\I18n\Translator\Loader\RemoteLoaderInterface', $loader); } -} \ No newline at end of file +} diff --git a/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/Factory/DoctrineLoaderFactoryTest.php b/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/Factory/DoctrineLoaderFactoryTest.php index 382681d..0116b13 100644 --- a/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/Factory/DoctrineLoaderFactoryTest.php +++ b/test/BsbDoctrineTranslationLoaderTest/I18n/Translator/Loader/Factory/DoctrineLoaderFactoryTest.php @@ -2,7 +2,6 @@ namespace BsbDoctrineTranslationLoaderTest\I18n\Translator\Loader; -use BsbDoctrineTranslationLoader\I18n\Translator\Loader\Doctrine; use BsbDoctrineTranslationLoader\I18n\Translator\Loader\Factory\DoctrineLoaderFactory; use BsbDoctrineTranslationLoaderTest\Framework\TestCase; @@ -40,4 +39,4 @@ public function testCanCreateService() $this->assertInstanceOf('BsbDoctrineTranslationLoader\I18n\Translator\Loader\DoctrineLoader', $service); } -} \ No newline at end of file +} diff --git a/test/BsbDoctrineTranslationLoaderTest/Service/MvcTranslatorDelegatorFactoryTest.php b/test/BsbDoctrineTranslationLoaderTest/Service/MvcTranslatorDelegatorFactoryTest.php new file mode 100644 index 0000000..de98343 --- /dev/null +++ b/test/BsbDoctrineTranslationLoaderTest/Service/MvcTranslatorDelegatorFactoryTest.php @@ -0,0 +1,42 @@ +getMock('Zend\ServiceManager\ServiceManager'); + + $loaderPluginManager = $this->getMockBuilder('Zend\I18n\Translator\LoaderPluginManager') + ->disableOriginalConstructor() + ->getMock(); + + $translator = $this->getMockBuilder('Zend\I18n\Translator\Translator') + ->disableOriginalConstructor() + ->getMock(); + + $translator->expects($this->once())->method('getPluginManager')->willReturn($loaderPluginManager); + $loaderPluginManager->expects($this->once())->method('setServiceLocator')->with($serviceLocator); + + $loaderPluginManager + ->expects($this->once()) + ->method('setFactory') + ->with( + 'BsbDoctrineTranslationLoader', + 'BsbDoctrineTranslationLoader\I18n\Translator\Loader\Factory\DoctrineLoaderFactory' + ); + + $callback = function () use ($translator) { + return $translator; + }; + + $delegator = new MvcTranslatorDelegatorFactory(); + + $delegator->createDelegatorWithName($serviceLocator, 'xxx', 'xxx', $callback); + + } +} diff --git a/test/BsbDoctrineTranslationLoaderTest/Util/ConfigManipulateTest.php b/test/BsbDoctrineTranslationLoaderTest/Util/ConfigManipulateTest.php index 963e1bc..ef792ee 100644 --- a/test/BsbDoctrineTranslationLoaderTest/Util/ConfigManipulateTest.php +++ b/test/BsbDoctrineTranslationLoaderTest/Util/ConfigManipulateTest.php @@ -1,8 +1,8 @@ assertEquals($expected, $actual); } -} \ No newline at end of file + + public function testOnMergeConfig() + { + $inputConfig = array( + 'bsb_doctrine_translation_loader' => array( + 'entity_manager' => 'orm_default', + 'doctrine' => array( + ConfigManipulate::EM_REPLACE_TOKEN => 'bar' + ), + ), + 'doctrine' => array() + ); + $outputConfig = array( + 'bsb_doctrine_translation_loader' => array( + 'entity_manager' => 'orm_default', + ), + 'doctrine' => array( + 'orm_default' => 'bar', + ) + ); + + $event = new \Zend\ModuleManager\ModuleEvent(); + $configListener = $this->getMock('Zend\ModuleManager\Listener\ConfigMergerInterface'); + + $event->setConfigListener($configListener); + + $configListener->expects($this->once())->method('getMergedConfig')->with(false)->willReturn($inputConfig); + $configListener->expects($this->once())->method('setMergedConfig')->with($outputConfig); + + ConfigManipulate::onMergeConfig($event); + } +}