Skip to content

Instantly share code, notes, and snippets.

@Raistlfiren
Last active February 8, 2016 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raistlfiren/911f4f924956f4fc2bce to your computer and use it in GitHub Desktop.
Save Raistlfiren/911f4f924956f4fc2bce to your computer and use it in GitHub Desktop.
<?php
$app = new App();
$app->post('/', function(ServerRequestInterface $request, ResponseInterface $response) {
//ERROR on functional test - Cannot modify header information - headers already sent by
$filename = filter_var($filename, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=\"$filename\"");
});
//Functional test
$_FILES = 'csvFileToProcess' => [
'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '../Resources/GenericExport.csv',
'name' => 'GenericExport.csv',
'type' => 'text/csv',
'error' => 0,
'size' => 4256,
];
$env = Environment::mock([
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'POST'
]);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$files = UploadedFile::createFromEnvironment(Environment::mock());
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$this->request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body, $files);
$this->response = new Response();
$response = $app($this->request, $this->response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment