From 8c9b22e3161da4568159f76fc9b2727a926435cf Mon Sep 17 00:00:00 2001 From: Stephane DECOCK Date: Thu, 19 Aug 2021 17:01:06 +0200 Subject: [PATCH 1/2] Allow to fetch translation with symlink Fixes #107 --- src/Translation/Finder/TranslationFilesFinder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Translation/Finder/TranslationFilesFinder.php b/src/Translation/Finder/TranslationFilesFinder.php index 914c740..4224511 100644 --- a/src/Translation/Finder/TranslationFilesFinder.php +++ b/src/Translation/Finder/TranslationFilesFinder.php @@ -54,6 +54,7 @@ private function getFiles(string $path): iterable $finder ->ignoreUnreadableDirs() + ->followLinks() ->in($path . '/translations') ; From 9c977f4a6d2c1e00f014d944c79c1f96f02095f5 Mon Sep 17 00:00:00 2001 From: Roshyo Date: Thu, 7 Jul 2022 15:17:36 +0200 Subject: [PATCH 2/2] Add test and fix PHPSpec --- .../Finder/TranslationFilesFinderSpec.php | 10 ++++--- .../private/translations/messages.fr.yml | 4 +++ .../MyTheme/translations/messages.fr.yml | 1 + .../Finder/TranslationFilesFinderTest.php | 28 +++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/Application/private/translations/messages.fr.yml create mode 120000 tests/Application/themes/MyTheme/translations/messages.fr.yml create mode 100644 tests/Translation/Finder/TranslationFilesFinderTest.php diff --git a/spec/Translation/Finder/TranslationFilesFinderSpec.php b/spec/Translation/Finder/TranslationFilesFinderSpec.php index 9320f39..0c0b670 100644 --- a/spec/Translation/Finder/TranslationFilesFinderSpec.php +++ b/spec/Translation/Finder/TranslationFilesFinderSpec.php @@ -21,23 +21,24 @@ final class TranslationFilesFinderSpec extends ObjectBehavior { - function let(FinderFactoryInterface $finderFactory): void + public function let(FinderFactoryInterface $finderFactory): void { $this->beConstructedWith($finderFactory); } - function it_implements_translation_resource_finder_interface(): void + public function it_implements_translation_resource_finder_interface(): void { $this->shouldImplement(TranslationFilesFinderInterface::class); } - function it_returns_an_array_of_translation_resources_paths( + public function it_returns_an_array_of_translation_resources_paths( FinderFactoryInterface $finderFactory, Finder $finder, ): void { $finderFactory->create()->willReturn($finder); $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); + $finder->followLinks()->shouldBeCalled()->willReturn($finder); $finder->in('/theme/translations')->shouldBeCalled()->willReturn($finder); $finder->getIterator()->willReturn(new \ArrayIterator([ @@ -51,13 +52,14 @@ function it_returns_an_array_of_translation_resources_paths( ]); } - function it_does_not_provide_any_translation_resources_paths_if_translation_directory_does_not_exist( + public function it_does_not_provide_any_translation_resources_paths_if_translation_directory_does_not_exist( FinderFactoryInterface $finderFactory, Finder $finder, ): void { $finderFactory->create()->willReturn($finder); $finder->ignoreUnreadableDirs()->willReturn($finder); + $finder->followLinks()->willReturn($finder); $finder->in('/theme/translations')->willThrow(DirectoryNotFoundException::class); $this->findTranslationFiles('/theme')->shouldReturn([]); diff --git a/tests/Application/private/translations/messages.fr.yml b/tests/Application/private/translations/messages.fr.yml new file mode 100644 index 0000000..27ffdb5 --- /dev/null +++ b/tests/Application/private/translations/messages.fr.yml @@ -0,0 +1,4 @@ +test: + app: 'traductions' + theme: 'traductions' + parent_theme: 'traductions' diff --git a/tests/Application/themes/MyTheme/translations/messages.fr.yml b/tests/Application/themes/MyTheme/translations/messages.fr.yml new file mode 120000 index 0000000..080c2fd --- /dev/null +++ b/tests/Application/themes/MyTheme/translations/messages.fr.yml @@ -0,0 +1 @@ +../../../private/translations/messages.fr.yml \ No newline at end of file diff --git a/tests/Translation/Finder/TranslationFilesFinderTest.php b/tests/Translation/Finder/TranslationFilesFinderTest.php new file mode 100644 index 0000000..6cdeacc --- /dev/null +++ b/tests/Translation/Finder/TranslationFilesFinderTest.php @@ -0,0 +1,28 @@ +createMock(FinderFactoryInterface::class); + $finderFactory->method('create')->willReturn($finder); + + $translationsFilesFinder = new TranslationFilesFinder($finderFactory); + $files = $translationsFilesFinder->findTranslationFiles('tests/Application/themes/MyTheme'); + + $this->assertContains('tests/Application/themes/MyTheme/translations/messages.fr.yml', $files); + } +}