Skip to content

Commit

Permalink
replacing recursive data merging in dataProvider with generator (#7959)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchezzzhak authored Dec 20, 2024
1 parent c844d7d commit 37578a0
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Tests/DeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down

0 comments on commit 37578a0

Please sign in to comment.