From fedfeb94a3c735d53467a06e3d9c0341098d705e Mon Sep 17 00:00:00 2001 From: Alexsandr Tutik Date: Fri, 20 Dec 2024 10:48:57 +0300 Subject: [PATCH] replacing recursive data merging in dataProvider with generator --- Tests/DeviceDetectorTest.php | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Tests/DeviceDetectorTest.php b/Tests/DeviceDetectorTest.php index cf761683ab..a74859cc5b 100644 --- a/Tests/DeviceDetectorTest.php +++ b/Tests/DeviceDetectorTest.php @@ -247,9 +247,8 @@ public function testParse(array $fixtureData): void $this->assertEquals($fixtureData, $uaInfo, $errorMessage); } - public function getFixtures(): array + public function getFixtures(): \Generator { - $fixtures = []; $fixtureFiles = \glob(\realpath(__DIR__) . '/fixtures/*.yml'); foreach ($fixtureFiles as $fixturesPath) { @@ -260,12 +259,10 @@ public function getFixtures(): array continue; } - $fixtures = \array_merge(\array_map(static function ($elem) { - return [$elem]; - }, $typeFixtures), $fixtures); + foreach ($typeFixtures as $fixture) { + yield [$fixture]; + } } - - return $fixtures; } /** @@ -301,20 +298,17 @@ public function testParseClient(array $fixtureData): void $this->assertEquals($fixtureData['client'], $uaInfo['client'], $messageError); } - public function getFixturesClient(): array + public function getFixturesClient(): \Generator { - $fixtures = []; $fixtureFiles = \glob(\realpath(__DIR__) . '/Parser/Client/fixtures/*.yml'); foreach ($fixtureFiles as $fixturesPath) { $typeFixtures = \Spyc::YAMLLoad($fixturesPath); - $fixtures = \array_merge(\array_map(static function ($elem) { - return [$elem]; - }, $typeFixtures), $fixtures); + foreach ($typeFixtures as $fixture) { + yield [$fixture]; + } } - - return $fixtures; } /** @@ -341,20 +335,17 @@ public function testParseDevice(array $fixtureData): void $this->assertEquals($fixtureData['device'], $uaInfo['device']); } - public function getFixturesDevice(): array + public function getFixturesDevice(): \Generator { - $fixtures = []; $fixtureFiles = \glob(\realpath(__DIR__) . '/Parser/Device/fixtures/*.yml'); foreach ($fixtureFiles as $fixturesPath) { $typeFixtures = \Spyc::YAMLLoad($fixturesPath); - $fixtures = \array_merge(\array_map(static function ($elem) { - return [$elem]; - }, $typeFixtures), $fixtures); + foreach ($typeFixtures as $fixture) { + yield [$fixture]; + } } - - return $fixtures; } public function getFixturesDeviceTypeFromClientHints(): array