Skip to content

Fatal error when using closure in callback matcher #33

@klinki

Description

@klinki

Hi,
I'm trying to create a mock with headers validation. I'm using callback for that.

I'm getting this error:

Fatal error: Function name must be a string in /vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(210) : eval()'d code on line 2

My code looks like this:

$method = 'POST';
$path = '/path';
$requestHeaders = [
   'Content-Type' => 'application/json'
];

$this->http->mock
            ->when()
            ->methodIs($method)
            ->pathIs($path)
            ->callback(static function(Request $request) use($requestHeaders) {
                foreach ($requestHeaders as $header => $value) {
                    if (!$request->hasHeader($header) || $request->getHeader($header) != $value) {
                        return false;
                    }
                }
                return true;
            })
            ->then()
            ->statusCode(200)
           ->body('ok')
           ->end();

Because of that bug, I cannot validate expected request headers. Could you please provide some alternative method to validate request headers until this issue is fixed?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions