From a072d93027dda99eb433d8e7d6828164ee5f2d1a Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Wed, 12 Jun 2024 18:31:58 +0200
Subject: [PATCH] [TASK] Reduce memory usage of a greedy unit test

> Build/Scripts/runTests.sh

Before:
Memory: 469.06 MB

After:
Memory: 373.02 MB

Reason: phpunit executes data providers early and keeps
data sets in memory. The "xml parser big content" tests
create megabytes of data kept in memory. Moving the data
generation from data providers to the test execution
reduces overall memory usage significantly.

Resolves: #104076
Releases: main, 12.4, 11.5
Change-Id: I0ad49824fc1d4c309158b74474853d36af22ffb5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84669
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Unit/Serializer/Typo3XmlParserTest.php    | 50 +++++--------------
 1 file changed, 13 insertions(+), 37 deletions(-)

diff --git a/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php b/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php
index 3d90e2b6e15a..1ee28d6dea4c 100644
--- a/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php
+++ b/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php
@@ -347,52 +347,28 @@ final class Typo3XmlParserTest extends UnitTestCase
         );
     }
 
-    /**
-     * @return array[]
-     */
     public static function decodeHandlesBigXmlContentDataProvider(): array
     {
         return [
-            '1mb' => [
-                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
-                <T3FlexForms>
-                    <data>
-                        <field index="settings.persistenceIdentifier">
-                            <value index="vDEF">' . str_repeat('1', 1024 * 1024) . '</value>
-                        </field>
-                    </data>
-                </T3FlexForms>',
-                str_repeat('1', 1024 * 1024),
-            ],
-            '5mb' => [
-                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
-                <T3FlexForms>
-                    <data>
-                        <field index="settings.persistenceIdentifier">
-                            <value index="vDEF">' . str_repeat('1', 5 * 1024 * 1024) . '</value>
-                        </field>
-                    </data>
-                </T3FlexForms>',
-                str_repeat('1', 5 * 1024 * 1024),
-            ],
-            '10mb' => [
-                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
-                <T3FlexForms>
-                    <data>
-                        <field index="settings.persistenceIdentifier">
-                            <value index="vDEF">' . str_repeat('1', 10 * 1024 * 1024) . '</value>
-                        </field>
-                    </data>
-                </T3FlexForms>',
-                str_repeat('1', 10 * 1024 * 1024),
-            ],
+            '1mb' => [1],
+            '5mb' => [5],
+            '10mb' => [10],
         ];
     }
 
     #[DataProvider('decodeHandlesBigXmlContentDataProvider')]
     #[Test]
-    public function decodeHandlesBigXmlContent(string $input, string $testValue): void
+    public function decodeHandlesBigXmlContent(int $megabytes): void
     {
+        $input = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+            <T3FlexForms>
+                <data>
+                    <field index="settings.persistenceIdentifier">
+                        <value index="vDEF">' . str_repeat('1', $megabytes * 1024 * 1024) . '</value>
+                    </field>
+                </data>
+            </T3FlexForms>';
+        $testValue = str_repeat('1', $megabytes * 1024 * 1024);
         $xmlDecoder = new Typo3XmlParser();
         $expected = [
             'data' => [
-- 
GitLab