Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with Lumen 6 under PHP 7.2 #20

Open
natanaugusto opened this issue Jan 16, 2020 · 2 comments
Open

Incompatible with Lumen 6 under PHP 7.2 #20

natanaugusto opened this issue Jan 16, 2020 · 2 comments

Comments

@natanaugusto
Copy link

natanaugusto commented Jan 16, 2020

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
Copy link
Author

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;
}

@HenkPoley
Copy link
Contributor

I think this is the same as Issue #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants