From 62bc876bc11ab533de263b45bbfe2b78815ede1d Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 17 Dec 2024 09:34:41 -0500 Subject: [PATCH] Fix more tests. --- module/VuFind/src/VuFindTest/Feature/TranslatorTrait.php | 6 +++++- .../src/VuFindTest/View/Helper/Root/TranslateTest.php | 5 +---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/module/VuFind/src/VuFindTest/Feature/TranslatorTrait.php b/module/VuFind/src/VuFindTest/Feature/TranslatorTrait.php index 9a35efc24b0d..ee468e9fc22e 100644 --- a/module/VuFind/src/VuFindTest/Feature/TranslatorTrait.php +++ b/module/VuFind/src/VuFindTest/Feature/TranslatorTrait.php @@ -56,7 +56,11 @@ protected function getMockTranslator(array $translations, string $locale = 'en') $callback = function ($str, $domain) use ($translations) { return $translations[$domain][$str] ?? $str; }; - $translator = $this->createMock(Translator::class); + $translator = $this->getMockBuilder(Translator::class) + ->disableOriginalConstructor() + ->onlyMethods(['translate']) + ->addMethods(['getLocale']) + ->getMock(); $translator->expects($this->any())->method('translate')->willReturnCallback($callback); $translator->expects($this->any())->method('getLocale')->willReturn($locale); return $translator; diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php index 033a5f1e87c2..34c472511b65 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php @@ -457,10 +457,7 @@ public function testLocaleWithoutTranslator(): void public function testLocaleWithTranslator(): void { $translate = new Translate(); - $translator = $this->createMock(\Laminas\Mvc\I18n\Translator::class); - $translator->expects($this->once())->method('getLocale') - ->will($this->returnValue('foo')); - $translate->setTranslator($translator); + $translate->setTranslator($this->getMockTranslator([], 'foo')); $this->assertEquals('foo', $translate->getTranslatorLocale()); }