From 9116d8a9cb1d055b3e9f040715f5df44d1ee2fbf Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 5 Nov 2024 15:45:20 +1300 Subject: [PATCH] FIX Anonymous function use statements in text collector --- src/i18n/TextCollection/i18nTextCollector.php | 9 +++- tests/php/i18n/i18nTextCollectorTest.php | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/i18n/TextCollection/i18nTextCollector.php b/src/i18n/TextCollection/i18nTextCollector.php index 3d3d6fa6f8f..7bc44598b56 100644 --- a/src/i18n/TextCollection/i18nTextCollector.php +++ b/src/i18n/TextCollection/i18nTextCollector.php @@ -602,6 +602,7 @@ public function collectFromCode($content, $fileName, Module $module) $entities = []; $tokens = token_get_all("getManifest()->getModule('i18ntestmodule'); + $php = <<someMethod(_t( + MyClass::class . '.SOMETHING_A', + 'something a', + )); + }); + } + + public function getNewLinesWithSomething(\$class, \$something) { + Deprecation::withSuppressedNotice(function () use (\$something) { + \$this->someMethod(_t( + MyClass::class . '.SOMETHING_B', + 'something {something}', + ['something' => \$something] + )); + }); + } + + public function getNewLinesWithSomething(\$class, \$something) { + Deprecation::withSuppressedNotice(function ( + \$myparam + ) use (\$something) { + \$this->someMethod(_t( + MyClass::class . '.SOMETHING_C', + 'something {something} {myparam}', + ['something' => \$something, 'myparam' => \$myparam] + )); + }); + } +} +PHP; + $this->assertEquals( + [ + 'SilverStripe\\Framework\\Core\\MyClass.SOMETHING_A' => "something a", + 'SilverStripe\\Framework\\Core\\MyClass.SOMETHING_B' => "something {something}", + 'SilverStripe\\Framework\\Core\\MyClass.SOMETHING_C' => "something {something} {myparam}", + ], + $c->collectFromCode($php, null, $mymodule) + ); + } + public function testCollectFromEntityProvidersInWebRoot() { // Collect from i18nProviderClass