From 7c35c82f8fc9c939aa1f12fdd5897a452bb1cfa8 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 7 Apr 2020 12:17:04 +0200 Subject: [PATCH 1/4] Added argument to CustomTag service --- src/bundle/Resources/config/services/ui_config/mappers.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bundle/Resources/config/services/ui_config/mappers.yml b/src/bundle/Resources/config/services/ui_config/mappers.yml index da3be525c6..a9e1263775 100644 --- a/src/bundle/Resources/config/services/ui_config/mappers.yml +++ b/src/bundle/Resources/config/services/ui_config/mappers.yml @@ -19,6 +19,7 @@ services: EzSystems\EzPlatformAdminUi\UI\Config\Mapper\FieldType\RichText\CustomTag: autowire: true arguments: + $translator: '@translator' $customTagsConfiguration: '%ezplatform.ezrichtext.custom_tags%' $translationDomain: '%ezplatform.field_type.ezrichtext.custom_tags.translation_domain%' $customTagAttributeMappers: !tagged ezplatform.admin_ui.richtext_custom_tag_attribute_mapper From a49cec7b4722dcf819dc892f97c6adf41451f29b Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 7 Apr 2020 13:22:20 +0200 Subject: [PATCH 2/4] Splited Translator argument to two separete for TranslatorInterface and TranslatorBagInterface --- .../config/services/ui_config/mappers.yml | 1 + .../Mapper/FieldType/RichText/CustomTag.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/bundle/Resources/config/services/ui_config/mappers.yml b/src/bundle/Resources/config/services/ui_config/mappers.yml index a9e1263775..25a607d650 100644 --- a/src/bundle/Resources/config/services/ui_config/mappers.yml +++ b/src/bundle/Resources/config/services/ui_config/mappers.yml @@ -20,6 +20,7 @@ services: autowire: true arguments: $translator: '@translator' + $translatorBag: '@translator' $customTagsConfiguration: '%ezplatform.ezrichtext.custom_tags%' $translationDomain: '%ezplatform.field_type.ezrichtext.custom_tags.translation_domain%' $customTagAttributeMappers: !tagged ezplatform.admin_ui.richtext_custom_tag_attribute_mapper diff --git a/src/lib/UI/Config/Mapper/FieldType/RichText/CustomTag.php b/src/lib/UI/Config/Mapper/FieldType/RichText/CustomTag.php index b1e22da7d0..29e9abb8e4 100644 --- a/src/lib/UI/Config/Mapper/FieldType/RichText/CustomTag.php +++ b/src/lib/UI/Config/Mapper/FieldType/RichText/CustomTag.php @@ -11,7 +11,8 @@ use EzSystems\EzPlatformAdminUi\UI\Config\Mapper\FieldType\RichText\CustomTag\AttributeMapper; use RuntimeException; use Symfony\Component\Asset\Packages; -use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorBagInterface; +use Symfony\Component\Translation\TranslatorInterface; use Traversable; /** @@ -22,9 +23,12 @@ class CustomTag /** @var array */ private $customTagsConfiguration; - /** @var Translator */ + /** @var \Symfony\Component\Translation\TranslatorInterface */ private $translator; + /** @var \Symfony\Component\Translation\TranslatorBagInterface */ + private $translatorBag; + /** @var Packages */ private $packages; @@ -44,20 +48,23 @@ class CustomTag * both TranslatorInterface and TranslatorBagInterface. * * @param array $customTagsConfiguration - * @param \Symfony\Component\Translation\Translator $translator + * @param \Symfony\Component\Translation\TranslatorInterface $translator + * @param \Symfony\Component\Translation\TranslatorBagInterface $translatorBag * @param string $translationDomain * @param \Symfony\Component\Asset\Packages $packages * @param \Traversable $customTagAttributeMappers */ public function __construct( array $customTagsConfiguration, - Translator $translator, + TranslatorInterface $translator, + TranslatorBagInterface $translatorBag, string $translationDomain, Packages $packages, Traversable $customTagAttributeMappers ) { $this->customTagsConfiguration = $customTagsConfiguration; $this->translator = $translator; + $this->translatorBag = $translatorBag; $this->translationDomain = $translationDomain; $this->packages = $packages; $this->customTagAttributeMappers = $customTagAttributeMappers; @@ -169,7 +176,7 @@ private function translateLabels(array $config): array continue; } - $transCatalogue = $this->translator->getCatalogue(); + $transCatalogue = $this->translatorBag->getCatalogue(); foreach ($tagConfig['attributes'] as $attributeName => $attributeConfig) { $config[$tagName]['attributes'][$attributeName]['label'] = $this->translator->trans( /** @Ignore */ From f43e08047689a1b37a8962393caf3cb98cb9a70a Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 7 Apr 2020 13:36:22 +0200 Subject: [PATCH 3/4] Fixed CustomTagTest --- .../Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php b/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php index 8d1e9e1991..d2569b9676 100644 --- a/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php +++ b/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php @@ -32,6 +32,7 @@ public function testMapConfig(array $customTagsConfiguration, array $enabledCust $mapper = new CustomTag( $customTagsConfiguration, $this->getTranslatorMock(), + $this->getTranslatorMock(), 'custom_tags', $this->getPackagesMock(), new ArrayObject([ From 8c72a020245bf22ef482cb97aaa3bdabc65b211f Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Wed, 8 Apr 2020 12:04:15 +0200 Subject: [PATCH 4/4] Splited TranslatorMock in test to TranslatorInterfaceMock and TranslatorBagMock --- .../FieldType/RichText/CustomTagTest.php | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php b/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php index d2569b9676..9eb5189476 100644 --- a/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php +++ b/src/lib/Tests/UI/Config/Mapper/FieldType/RichText/CustomTagTest.php @@ -13,7 +13,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Asset\Packages; use Symfony\Component\Translation\MessageCatalogueInterface; -use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorBagInterface; +use Symfony\Component\Translation\TranslatorInterface; /** * UI Config Mapper test for RichText Custom Tags configuration. @@ -31,8 +32,8 @@ public function testMapConfig(array $customTagsConfiguration, array $enabledCust { $mapper = new CustomTag( $customTagsConfiguration, - $this->getTranslatorMock(), - $this->getTranslatorMock(), + $this->getTranslatorInterfaceMock(), + $this->getTranslatorBagInterfaceMock(), 'custom_tags', $this->getPackagesMock(), new ArrayObject([ @@ -164,7 +165,22 @@ public function providerForTestMapConfig(): array /** * @return \Symfony\Component\Translation\TranslatorInterface|\PHPUnit\Framework\MockObject\MockObject */ - private function getTranslatorMock(): MockObject + private function getTranslatorInterfaceMock(): MockObject + { + $translatorInterfaceMock = $this->createMock(TranslatorInterface::class); + $translatorInterfaceMock + ->expects($this->any()) + ->method('trans') + ->withAnyParameters() + ->willReturnArgument(0); + + return $translatorInterfaceMock; + } + + /** + * @return \Symfony\Component\Translation\TranslatorBagInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private function getTranslatorBagInterfaceMock(): MockObject { $catalogueMock = $this->createMock(MessageCatalogueInterface::class); $catalogueMock @@ -173,21 +189,15 @@ private function getTranslatorMock(): MockObject ->withAnyParameters() ->willReturn(false); - $translatorMock = $this->createMock(Translator::class); - $translatorMock + $translatorBagMock = $this->createMock(TranslatorBagInterface::class); + $translatorBagMock ->expects($this->any()) ->method('getCatalogue') ->willReturn( $catalogueMock ); - $translatorMock - ->expects($this->any()) - ->method('trans') - ->withAnyParameters() - ->willReturnArgument(0); - - return $translatorMock; + return $translatorBagMock; } /**