Created
November 9, 2018 05:59
-
-
Save t-kuni/662e24864bde4e9cb49c6974e2f26f91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function buildTestCases($variations) { | |
$iterate = function($variations, $depth = 0, $indexies = []) use (&$iterate) { | |
$keys = array_keys($variations); | |
if ($depth >= count($keys)) { | |
yield $indexies; | |
} else { | |
$key = $keys[$depth]; | |
for ($i = 0; $i < count($variations[$key]); $i++) { | |
$val = $variations[$key][$i]; | |
$iterator = $iterate($variations, $depth + 1, array_merge($indexies, [$key => $val])); | |
foreach ($iterator as $variation) { | |
yield $variation; | |
} | |
} | |
} | |
}; | |
$testCases = []; | |
$no = 1; | |
foreach ($iterate($variations) as $variation) { | |
$title = $no++ . "."; | |
$keys = array_keys($variation); | |
$title = array_reduce($keys, function($title, $key) use ($variation) { | |
$val = $variation[$key]; | |
return "{$title} {$key}:{$val}"; | |
}, $title); | |
$testCases = array_merge($testCases, [ | |
$title => [$variation] | |
]); | |
} | |
return $testCases; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment