lumen-testing icon indicating copy to clipboard operation
lumen-testing copied to clipboard

Incompatible with Lumen 6 under PHP 7.2

Open natanaugusto opened this issue 5 years ago • 2 comments

I try to use the package with Lumen 6 and PHP 7.2 and this not work.

The request does not pass the values.

// I try
$this->json('POST', 'my-route', ['value1' => 1, 'value2' => 2]);

// And receive
$request->all() // []

natanaugusto avatar Jan 16 '20 21:01 natanaugusto

I've overwritten this fellow methods on my TestCase, and now the lumen-testing seems to work with lumen 6:

/**
 * Call the given URI and return the Response.
 *
 * @param  string  $method
 * @param  string  $uri
 * @param  array  $parameters
 * @param  array  $cookies
 * @param  array  $files
 * @param  array  $server
 * @param  string  $content
 * @return \Illuminate\Http\Response
 */
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
    $this->currentUri = $this->prepareUrlForRequest($uri);

    $symfonyRequest = SymfonyRequest::create(
        $this->currentUri, $method, $parameters,
        $cookies, $files, $server, $content
    );

    $this->app['request'] = LumenRequest::createFromBase($symfonyRequest);

    return $this->response = $this->createTestResponse(
        $this->app->prepareResponse($this->app->handle($this->app['request']))
    );
}

/**
 * Extract the file uploads from the given data array.
 *
 * @param  array  $data
 * @return array
 */
protected function extractFilesFromDataArray(&$data)
{
    $files = [];

    foreach ($data as $key => $value) {
        if ($value instanceof SymfonyUploadedFile) {
            $files[$key] = $value;

            unset($data[$key]);
        }

        if (is_array($value)) {
            $files[$key] = $this->extractFilesFromDataArray($value);
            if (!empty($files[$key])) {
                unset($data[$key]);
            }
            $data[$key] = $value;
        }
    }

    return $files;
}

natanaugusto avatar Jan 23 '20 22:01 natanaugusto

I think this is the same as Issue #13

HenkPoley avatar Jul 07 '21 12:07 HenkPoley