RestContext::collectFakeData PHP Method

collectFakeData() public method

public collectFakeData ( string $dataKey, Behat\Gherkin\Node\TableNode $data ) : boolean
$dataKey string
$data Behat\Gherkin\Node\TableNode
return boolean
    public function collectFakeData($dataKey, \Behat\Gherkin\Node\TableNode $data)
    {
        $faker = Faker\Factory::create();
        $this->collectedData[$dataKey] = array();
        foreach ($data->getRows() as $key => $value) {
            if (strpos($value[1], '<<') !== false) {
                $functionName = str_replace('>>', '', str_replace('<<', '', $value[1]));
                $fakeValue = call_user_func_array(array($faker, $functionName), explode(',', $value[2]));
                if ($functionName == 'file' || $functionName == 'image') {
                    $fakeValue = new FormUpload($fakeValue);
                }
                if (strpos($value[0], '[') !== false) {
                    parse_str($value[0] . '=' . $fakeValue, $temp);
                    $temp = array($dataKey => $temp);
                    $this->collectedData = array_merge_recursive($this->collectedData, $temp);
                    continue;
                }
                $this->collectedData[$dataKey][$value[0]] = $fakeValue;
            } else {
                if (strpos($value[0], '[') !== false) {
                    parse_str($value[0] . '=' . $fakeValue, $temp);
                    $temp = array($dataKey => $temp);
                    $this->collectedData = array_merge_recursive($this->collectedData, $temp);
                    continue;
                }
                if (strpos($value[1], '(') !== false) {
                    $locationIndex = str_replace(')', '', str_replace('(', '', $value[1]));
                    $locationValue = $this->locations[$locationIndex];
                    parse_str($value[0] . '=' . $locationValue, $temp);
                    $temp = array($dataKey => $temp);
                    $this->collectedData = array_merge_recursive($this->collectedData, $temp);
                    continue;
                }
                $this->collectedData[$dataKey][$value[0]] = $value[1];
            }
        }
        return true;
    }