From d142619a69a2013cea532859a938399b5f1c5466 Mon Sep 17 00:00:00 2001 From: Levan Velijanashvili Date: Tue, 19 Dec 2023 01:38:40 +0400 Subject: [PATCH] Cover static method calls --- tests/TranslationTest.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/TranslationTest.php b/tests/TranslationTest.php index ce0eda9..8765a7b 100644 --- a/tests/TranslationTest.php +++ b/tests/TranslationTest.php @@ -31,23 +31,29 @@ public function testTranslationEquality(): void public function testTranslationKeyExtraction(): void { - $result = $this->tr->setSource('en')->setTarget('fr')->preserveParameters()->translate('Hello :name, how are :type_of_greeting?'); + $resultOne = GoogleTranslate::trans('Hello :name how are :type_of_greeting?', 'fr', 'en', preserveParameters: true); + $resultTwo = $this->tr->setSource('en')->setTarget('fr')->preserveParameters()->translate('Hello :name, how are :type_of_greeting?'); - $this->assertEquals('Bonjour :name, comment vont :type_of_greeting ?', $result, 'Translation should be correct with proper key extraction.'); + $this->assertEquals('Bonjour :name, comment vont :type_of_greeting ?', $resultOne, 'Translation should be correct with proper key extraction.'); + $this->assertEquals('Bonjour :name, comment vont :type_of_greeting ?', $resultTwo, 'Translation should be correct with proper key extraction.'); } public function testCanIgnoreTranslationKeyExtraction(): void { - $result = $this->tr->setSource('en')->setTarget('fr')->translate('Hello :name how are :greeting?'); + $resultOne = GoogleTranslate::trans('Hello :name how are :greeting?', 'fr', 'en'); + $resultTwo = $this->tr->setSource('en')->setTarget('fr')->translate('Hello :name how are :greeting?'); - $this->assertEquals('Bonjour :nom, comment allez-vous :salut ?', $result, 'Translation should be correct and ignores key extraction if not set.'); + $this->assertEquals('Bonjour :nom, comment allez-vous :salut ?', $resultOne, 'Translation should be correct and ignores key extraction if not set.'); + $this->assertEquals('Bonjour :nom, comment allez-vous :salut ?', $resultTwo, 'Translation should be correct and ignores key extraction if not set.'); } public function testCanCustomizeExtractionPattern(): void { - $result = $this->tr->setSource('en')->setTarget('fr')->preserveParameters('/\{\{([^}]+)\}\}/')->translate('Hello {{name}}, how are {{type_of_greeting}}?'); + $resultOne = GoogleTranslate::trans('Hello {{name}}, how are {{type_of_greeting}}?', 'fr', 'en', preserveParameters: '/\{\{([^}]+)\}\}/'); + $resultTwo = $this->tr->setSource('en')->setTarget('fr')->preserveParameters('/\{\{([^}]+)\}\}/')->translate('Hello {{name}}, how are {{type_of_greeting}}?'); - $this->assertEquals('Bonjour {{name}}, comment vont {{type_of_greeting}} ?', $result, 'Translation should be correct and ignores key extraction if not set.'); + $this->assertEquals('Bonjour {{name}}, comment vont {{type_of_greeting}} ?', $resultOne, 'Translation should be correct and ignores key extraction if not set.'); + $this->assertEquals('Bonjour {{name}}, comment vont {{type_of_greeting}} ?', $resultTwo, 'Translation should be correct and ignores key extraction if not set.'); } public function testNewerLanguageTranslation(): void