protected function writeToFile(array &$stepActionParams, array &$endpointOptions, array &$context)
    {
        $stepParamsResolver = new OptionsResolver();
        $stepParamsResolver->setRequired([
            self::PARAM_FILE_NAME,
            self::PARAM_CSV_ROWS,
        ]);
        $params = $stepParamsResolver->resolve($stepActionParams);

        $filePath = $params[self::PARAM_FILE_NAME];
        $fullPath = $this->getRootPath($endpointOptions).DIRECTORY_SEPARATOR.$filePath;

        $rows = $params[self::PARAM_CSV_ROWS];

        //open the file, reset the pointer to zero, create it if not already created
        $fileHandle = fopen($fullPath, 'w');

        foreach ($rows as $row) {
            if (!is_array($row)) {
                $type = gettype($row);
                throw new \InvalidArgumentException("Row in Rows is not an array, {$type} given.");
            }

            fputcsv($fileHandle, $row, $endpointOptions[CsvConfigurableProtocol::OPTION_DELIMITER], $endpointOptions[CsvConfigurableProtocol::OPTION_ENCLOSURE], $endpointOptions[CsvConfigurableProtocol::OPTION_ESCAPE_CHAR]);
        }

        fclose($fileHandle);
    }