2 namespace Consolidation\TestUtils;
7 * Given an array of test data, where each element is
8 * data to pass to a unit test AND each unit test requires
9 * only scalar or object test value, find each array
10 * in each test, and build all of the permutations for all
11 * of the data provided in arrays.
13 public static function expandProviderDataArrays($tests)
17 foreach($tests as $test) {
18 $subsitutionIndex = 1;
19 $permutationData = [];
22 foreach($test as $testValue) {
23 if (is_array($testValue)) {
24 $key = "{SUB$subsitutionIndex}";
25 $replacements[$key] = $testValue;
26 $permutationData[] = $key;
29 $permutationData[] = $testValue;
33 $permuted = static::expandDataMatrix([$permutationData], $replacements);
34 $result = array_merge($result, $permuted);
41 * Given an array of test data, where each element is
42 * data to pass to a unit test, expand all of the
43 * permutations of $replacements, where each key
44 * holds the placeholder value, and the value holds
45 * an array of replacement values.
47 public static function expandDataMatrix($tests, $replacements)
49 foreach($replacements as $substitute => $values) {
50 $tests = static::expandOneValue($tests, $substitute, $values);
56 * Given an array of test data, where each element is
57 * data to pass to a unit test, find any element in any
58 * one test item whose value is exactly $substitute.
59 * Make a new test item for every item in $values, using
60 * each as the substitution for $substitute.
62 public static function expandOneValue($tests, $substitute, $values)
66 foreach($tests as $test) {
67 $position = array_search($substitute, $test);
68 if ($position === FALSE) {
72 foreach($values as $replacement) {
73 $test[$position] = $replacement;