summaryrefslogtreecommitdiff
path: root/tests/Unit/Helpers/TranslationServiceProviderTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-08 12:48:08 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-09 12:11:12 +0200
commit222c9fed7d4ca2b3b44c05907fbb7080c1efd342 (patch)
tree62b1bfa9233000985331b9dea703d51dc24515a2 /tests/Unit/Helpers/TranslationServiceProviderTest.php
parent2d6bca1357faff28bc1f86a56b432cc463ff7574 (diff)
parent8257864829ffdfb410f05e0dd0a9c781f48b741a (diff)
Merge remote-tracking branch 'MyIgel/templating'
Diffstat (limited to 'tests/Unit/Helpers/TranslationServiceProviderTest.php')
-rw-r--r--tests/Unit/Helpers/TranslationServiceProviderTest.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/Unit/Helpers/TranslationServiceProviderTest.php b/tests/Unit/Helpers/TranslationServiceProviderTest.php
new file mode 100644
index 00000000..c5ba7386
--- /dev/null
+++ b/tests/Unit/Helpers/TranslationServiceProviderTest.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers;
+
+use Engelsystem\Config\Config;
+use Engelsystem\Helpers\TranslationServiceProvider;
+use Engelsystem\Helpers\Translator;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\HttpFoundation\Session\Session;
+
+class TranslationServiceProviderTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Helpers\TranslationServiceProvider::register()
+ */
+ public function testRegister()
+ {
+ $app = $this->getApp(['make', 'instance', 'get']);
+ /** @var Config|MockObject $config */
+ $config = $this->createMock(Config::class);
+ /** @var Session|MockObject $session */
+ $session = $this->createMock(Session::class);
+ /** @var Translator|MockObject $translator */
+ $translator = $this->createMock(Translator::class);
+
+ /** @var TranslationServiceProvider|MockObject $serviceProvider */
+ $serviceProvider = $this->getMockBuilder(TranslationServiceProvider::class)
+ ->setConstructorArgs([$app])
+ ->setMethods(['initGettext', 'setLocale'])
+ ->getMock();
+
+ $serviceProvider->expects($this->once())
+ ->method('initGettext');
+
+ $app->expects($this->exactly(2))
+ ->method('get')
+ ->withConsecutive(['config'], ['session'])
+ ->willReturnOnConsecutiveCalls($config, $session);
+
+ $defaultLocale = 'fo_OO';
+ $locale = 'te_ST.WTF-9';
+ $locales = ['fo_OO' => 'Foo', 'fo_OO.BAR' => 'Foo (Bar)', 'te_ST.WTF-9' => 'WTF\'s Testing?'];
+ $config->expects($this->exactly(2))
+ ->method('get')
+ ->withConsecutive(
+ ['locales'],
+ ['default_locale']
+ )
+ ->willReturnOnConsecutiveCalls(
+ $locales,
+ $defaultLocale
+ );
+
+ $session->expects($this->once())
+ ->method('get')
+ ->with('locale', $defaultLocale)
+ ->willReturn($locale);
+ $session->expects($this->once())
+ ->method('set')
+ ->with('locale', $locale);
+
+ $app->expects($this->once())
+ ->method('make')
+ ->with(
+ Translator::class,
+ [
+ 'locale' => $locale,
+ 'locales' => $locales,
+ 'localeChangeCallback' => [$serviceProvider, 'setLocale']
+ ]
+ )
+ ->willReturn($translator);
+
+ $app->expects($this->exactly(2))
+ ->method('instance')
+ ->withConsecutive(
+ [Translator::class, $translator],
+ ['translator', $translator]
+ );
+
+ $serviceProvider->register();
+ }
+}
+
+